• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            使用Delegate具體如下:
            class QLineDelegate : public QStyledItemDelegate
            {
                Q_OBJECT
            public:
                QLineDelegate(QTableView
            * tableView);
            protected:
                
            void paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index) const;
                
            bool editorEvent(QEvent *event,
                                                     QAbstractItemModel 
            *model,
                                                     
            const QStyleOptionViewItem &option,
                                                     
            const QModelIndex &index) ;
            private:
                QPen         pen;
                QTableView
            *  view;
            };

            static QRect CheckBoxRect(const QStyleOptionViewItem &view_item_style_options)
            {
                QStyleOptionButton check_box_style_option;
                QRect check_box_rect 
            = QApplication::style()->subElementRect(
                    QStyle::SE_CheckBoxIndicator,
                    
            &check_box_style_option);

                QPoint check_box_point(view_item_style_options.rect.x() 
            +
                                       view_item_style_options.rect.width() 
            / 2 -
                                       check_box_rect.width() 
            / 2,
                                       view_item_style_options.rect.y() 
            +
                                       view_item_style_options.rect.height() 
            / 2 -
                                       check_box_rect.height() 
            / 2);
                
            return QRect(check_box_point, check_box_rect.size());
            }


            QLineDelegate::QLineDelegate(QTableView
            * tableView)
            {
                
            int gridHint = tableView->style()->styleHint(QStyle::SH_Table_GridLineColor, new QStyleOptionViewItemV4());
                QColor gridColor 
            = static_cast<QRgb>(gridHint);
                pen 
            = QPen(gridColor,0,tableView->gridStyle());
                view 
            = tableView;
            }

            void QLineDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,const QModelIndex& index)const
            {
                
            bool checked = index.model()->data(index, Qt::DisplayRole).toBool();

                
            if(index.column() == 0)
                {
                    QStyleOptionButton check_box_style_option;
                    check_box_style_option.state 
            |= QStyle::State_Enabled;
                    
            if(checked)
                    {
                        check_box_style_option.state 
            |= QStyle::State_On;
                    }
                    
            else
                    {
                        check_box_style_option.state 
            |= QStyle::State_Off;
                    }
                    check_box_style_option.rect 
            = CheckBoxRect(option);
                    QApplication::style()
            ->drawControl(QStyle::CE_CheckBox,&check_box_style_option,painter);
                }

                QStyledItemDelegate::paint(painter,option,index);
                QStyleOptionViewItem itemOption(option);
                
            if(itemOption.state & QStyle::State_HasFocus)
                    itemOption.state 
            = itemOption.state ^ QStyle::State_HasFocus;
                QStyledItemDelegate::paint(painter,itemOption,index);
                QPen oldPen 
            = painter->pen();
                painter
            ->setPen(pen);
                painter
            ->drawLine(option.rect.topRight(),option.rect.bottomRight());
                painter
            ->drawLine(itemOption.rect.bottomLeft(),itemOption.rect.bottomRight());
                painter
            ->setPen(oldPen);
            }

            bool QLineDelegate::editorEvent(QEvent *event,
                                               QAbstractItemModel 
            *model,
                                               
            const QStyleOptionViewItem &option,
                                               
            const QModelIndex &index) {
                
            if((event->type() == QEvent::MouseButtonRelease) ||
                    (
            event->type() == QEvent::MouseButtonDblClick))
                {
                    QMouseEvent 
            *mouse_event = static_cast<QMouseEvent*>(event);
                    
            if(mouse_event->button() != Qt::LeftButton ||
                       
            !CheckBoxRect(option).contains(mouse_event->pos()))
                    {
                        
            return false;
                    }

                    
            if(event->type() == QEvent::MouseButtonDblClick)
                    {
                        
            return true;
                    }
                }
                
            else if(event->type() == QEvent::KeyPress)
                {
                    
            if(static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space &&
                       static_cast
            <QKeyEvent*>(event)->key() != Qt::Key_Select)
                    {
                        
            return false;
                    }
                }
                
            else
                {
                    
            return false;
                }

                
            bool checked = index.model()->data(index, Qt::DisplayRole).toBool();
                
            return model->setData(index, !checked, Qt::EditRole);
            }
            不過有一個小問題,就是CheckBox旁邊有false/true字符
            posted on 2011-11-26 12:33 ccsdu2009 閱讀(5324) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久久久久综合网天天| MM131亚洲国产美女久久| 久久综合给合综合久久| 中文字幕无码av激情不卡久久| 狠狠精品干练久久久无码中文字幕 | 久久人人爽人人爽人人AV东京热 | 久久亚洲天堂| 久久亚洲精品国产精品| 国内精品久久久久久久久| 亚洲中文字幕久久精品无码喷水| 99久久国产热无码精品免费| 日本久久中文字幕| 99久久中文字幕| 精品久久久久久中文字幕大豆网| 国产精品一久久香蕉国产线看| 伊人久久大香线蕉精品不卡| 青青草原精品99久久精品66| 久久亚洲天堂| 久久精品免费大片国产大片| 久久婷婷五月综合色高清| 亚洲欧美日韩精品久久亚洲区| 国产高清美女一级a毛片久久w| 亚洲国产另类久久久精品| 色播久久人人爽人人爽人人片aV| 日本三级久久网| 久久AV高清无码| 久久无码人妻一区二区三区午夜 | 久久伊人影视| 久久精品成人免费观看97| 久久综合九色综合精品| 狠狠狠色丁香婷婷综合久久俺| 日韩AV无码久久一区二区| 日韩精品久久久久久久电影| 性做久久久久久免费观看| 色8激情欧美成人久久综合电| 国产精久久一区二区三区| 久久九九青青国产精品| 中文字幕亚洲综合久久2| 丰满少妇人妻久久久久久4| 精品无码久久久久久国产| 国产日韩久久免费影院|