• <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等多種語言 程序猿
            #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 閱讀(2576) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            亚洲国产精品综合久久网络| 99久久做夜夜爱天天做精品| 久久久中文字幕| 亚洲午夜久久久精品影院| 无码乱码观看精品久久| 99久久免费国产精精品| 久久精品视屏| 99久久综合狠狠综合久久止| 伊人精品久久久久7777| 99久久99久久久精品齐齐| 日韩美女18网站久久精品| 精品一区二区久久| 久久久久亚洲精品天堂| 亚洲国产成人精品无码久久久久久综合 | 国产情侣久久久久aⅴ免费| 热99re久久国超精品首页| 人妻精品久久久久中文字幕一冢本 | 狠狠色丁香久久综合五月| 久久人人青草97香蕉| 成人国内精品久久久久影院VR| 麻豆AV一区二区三区久久| 一本色道久久88综合日韩精品 | 久久亚洲国产中v天仙www| 久久综合狠狠综合久久| 无码人妻久久一区二区三区蜜桃| 国产AⅤ精品一区二区三区久久| 国产精品久久久久久久| 久久丫精品国产亚洲av不卡| 国产亚洲精久久久久久无码77777| 青青热久久国产久精品 | 久久精品欧美日韩精品| 无码精品久久久天天影视| 久久精品免费一区二区| 狠狠色丁香婷婷久久综合五月| 久久精品国产99久久香蕉| 久久99精品久久久久久秒播| 久久99精品久久久久久不卡 | 久久精品中文字幕无码绿巨人| 国产美女亚洲精品久久久综合| 77777亚洲午夜久久多喷| 色妞色综合久久夜夜|