• <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編程
             
            色欲久久久天天天综合网| 亚洲中文久久精品无码ww16 | 国产成人久久精品一区二区三区 | 99久久国产综合精品麻豆| 久久精品国产亚洲av高清漫画| 996久久国产精品线观看| 99久久婷婷免费国产综合精品| 亚洲综合久久综合激情久久| 欧美久久久久久午夜精品| 麻豆精品久久久久久久99蜜桃| 久久久久久久久久久久中文字幕| 秋霞久久国产精品电影院| 午夜精品久久久久久| 久久99毛片免费观看不卡| 久久精品国产亚洲一区二区三区| 777午夜精品久久av蜜臀| 国产精品久久永久免费| 久久婷婷五月综合97色直播| 2021精品国产综合久久| 久久综合鬼色88久久精品综合自在自线噜噜 | 亚洲精品午夜国产VA久久成人| 久久99精品国产麻豆宅宅| 欧美成人免费观看久久| 国产精品久久国产精品99盘| 麻豆精品久久久久久久99蜜桃| 91久久精品电影| 少妇人妻88久久中文字幕| 久久亚洲私人国产精品| 久久香综合精品久久伊人| 无遮挡粉嫩小泬久久久久久久| 狠狠综合久久综合88亚洲| 久久精品亚洲日本波多野结衣| 久久亚洲电影| 国产成人久久久精品二区三区| 久久国产乱子伦免费精品| 国产成人精品综合久久久久| 精品久久久久久无码人妻热| 99精品国产在热久久| 久久99国产综合精品女同| 久久天堂AV综合合色蜜桃网| 亚洲精品乱码久久久久久久久久久久 |