• <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++高級(jí)工程師 Android高級(jí)軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語(yǔ)言 程序猿
            #include <QtGui>

            class ItemDelegate : public QItemDelegate
            {
            public:
                ItemDelegate(QObject 
            *parent = 0)
                    : QItemDelegate(parent)
                {
                }
                
            virtual void drawCheck(QPainter *painter, const QStyleOptionViewItem &option,
                    
            const QRect &, Qt::CheckState state)const
                {
                    
            const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;

                    QRect checkRect 
            = QStyle::alignedRect(option.direction, Qt::AlignCenter,
                        check(option, option.rect, Qt::Checked).size(),
                        QRect(option.rect.x() 
            + textMargin, option.rect.y(),
                        option.rect.width() 
            - (textMargin * 2), option.rect.height()));
                    QItemDelegate::drawCheck(painter, option, checkRect, state);
                }
                
            virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option,
                    
            const QModelIndex &index)
                {
                    Q_ASSERT(
            event);
                    Q_ASSERT(model);

                    Qt::ItemFlags flags 
            = model->flags(index);
                    
            if(!(flags & Qt::ItemIsUserCheckable) || !(flags & Qt::ItemIsEnabled))
                        
            return false;

                    QVariant value 
            = index.data(Qt::CheckStateRole);
                    
            if(!value.isValid())
                        
            return false;

                    
            if(event->type() == QEvent::MouseButtonRelease)
                    {
                        
            const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
                        QRect checkRect 
            = QStyle::alignedRect(option.direction, Qt::AlignCenter,
                            check(option, option.rect, Qt::Checked).size(),
                            QRect(option.rect.x() 
            + textMargin, option.rect.y(),
                            option.rect.width() 
            - (2 * textMargin), option.rect.height()));
                        
            if (!checkRect.contains(static_cast<QMouseEvent*>(event)->pos()))
                            
            return false;
                    }
                    
            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;
                    }
                    Qt::CheckState state 
            = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
                        
            ? Qt::Unchecked : Qt::Checked);

                    
            //

                    
            return model->setData(index, state, Qt::CheckStateRole);
                }
                
            void drawFocus(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect) const
                {
                    QItemDelegate::drawFocus(painter, option, option.rect);
                }
            };

            static int ROWS = 3;
            static int COLS = 3;

            class Table : public QTableWidget
            {
            public:
                Table(QWidget 
            *parent = 0)
                    : QTableWidget(ROWS, COLS, parent)
                {
                    setItemDelegate(
            new ItemDelegate(this));
                    QTableWidgetItem 
            *item = 0;
                    
            for(int i=0; i<rowCount(); ++i)
                    {
                        
            for(int j=0; j<columnCount(); ++j)
                        {
                            setItem(i, j, item 
            = new QTableWidgetItem);
                            QTableViewItem;
                            item
            ->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
                            item
            ->setCheckState((i+j) % 2 == 0 ? Qt::Checked : Qt::Unchecked);
                        }
                    }
                }
            };

            int main(int argc, char **argv)
            {
                QApplication a(argc, argv);
                Table w;
                w.show();
                
            return a.exec();
            }
            posted on 2011-11-26 11:25 ccsdu2009 閱讀(2558) 評(píng)論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            国产午夜精品理论片久久影视| 久久久亚洲精品蜜桃臀| 久久精品人人做人人爽97| 无码人妻久久一区二区三区免费丨| 亚洲第一极品精品无码久久| 久久久久久久亚洲Av无码| 狠狠色婷婷综合天天久久丁香 | 亚洲国产视频久久| 久久久国产打桩机| 国产精品99久久不卡| 色偷偷88欧美精品久久久| 色妞色综合久久夜夜| 99久久99久久精品国产片果冻| 色欲综合久久躁天天躁| 国产99久久精品一区二区| 久久强奷乱码老熟女网站| 72种姿势欧美久久久久大黄蕉| 无码人妻久久一区二区三区蜜桃 | 色妞色综合久久夜夜| 久久精品国产亚洲欧美| 国产69精品久久久久观看软件| 岛国搬运www久久| 国产精品9999久久久久| 精品多毛少妇人妻AV免费久久| 久久本道伊人久久| 久久婷婷五月综合色高清| 久久婷婷五月综合色奶水99啪 | 久久亚洲春色中文字幕久久久| 久久99精品九九九久久婷婷| 国产成人精品久久免费动漫| 亚洲人成精品久久久久| 性做久久久久久久久| 狠狠久久综合伊人不卡| 国产精品99久久精品爆乳| 久久精品国产秦先生| 香港aa三级久久三级| 99久久免费国产精品热| 热re99久久精品国产99热| 蜜桃麻豆www久久| 99久久精品免费观看国产| 国产精品99久久精品爆乳|