• <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 閱讀(5309) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久天天躁狠狠躁夜夜2020老熟妇| 国产精品久久久久久一区二区三区 | 久久精品国产72国产精福利| 久久精品成人免费国产片小草| 日本精品久久久久中文字幕8| 久久99国产精品成人欧美| 日韩欧美亚洲综合久久影院Ds| 久久精品国产亚洲av麻豆图片 | 欧美久久天天综合香蕉伊| 久久99热这里只有精品国产| 国产精品久久久天天影视| 中文成人久久久久影院免费观看| 久久精品国产2020| 精品久久久久久无码人妻热| 久久午夜羞羞影院免费观看| 99热都是精品久久久久久| 欧美成人免费观看久久| 久久亚洲综合色一区二区三区| 无码国内精品久久综合88| 丁香五月综合久久激情| 无码人妻久久一区二区三区 | www.久久热.com| 久久综合亚洲色HEZYO国产| 久久免费精品一区二区| 色综合久久久久综合体桃花网 | 久久青青草原综合伊人| 无码久久精品国产亚洲Av影片| 久久久国产精品| 97超级碰碰碰碰久久久久| 久久婷婷五月综合97色一本一本| 一本色道久久综合| 无码人妻久久一区二区三区蜜桃| 久久婷婷久久一区二区三区| 国产午夜免费高清久久影院| 中文字幕久久波多野结衣av| 久久精品国产久精国产一老狼| 国产69精品久久久久APP下载| 亚洲国产精品一区二区三区久久 | 国产L精品国产亚洲区久久| 狠狠久久亚洲欧美专区 | 久久久久人妻精品一区|