• <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 閱讀(2573) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            久久国产免费直播| 99国产欧美久久久精品蜜芽| 秋霞久久国产精品电影院| 日韩精品国产自在久久现线拍 | 久久精品中文无码资源站| 漂亮人妻被中出中文字幕久久| 久久亚洲精品成人AV| 精品免费tv久久久久久久| 一极黄色视频久久网站| 久久亚洲私人国产精品| 久久久久九九精品影院| 99久久久精品| 久久精品一本到99热免费| 久久精品夜色噜噜亚洲A∨| 人妻无码久久一区二区三区免费 | 国产精品久久精品| 香蕉久久影院| 国产69精品久久久久9999| 精品久久久久久亚洲精品| 久久这里只有精品首页| 欧美精品丝袜久久久中文字幕 | 亚洲中文字幕无码久久综合网| 国内精品免费久久影院| 99久久99久久久精品齐齐| 亚洲成色www久久网站夜月| 久久精品国产精品亚洲| 久久久久久免费一区二区三区| 奇米影视7777久久精品| 国产激情久久久久久熟女老人 | 日韩久久久久久中文人妻| 久久久国产亚洲精品| 久久婷婷五月综合色99啪ak| 国产精品99久久久久久www| 日韩精品久久久久久| 99精品久久久久久久婷婷| 久久久中文字幕| 久久se精品一区二区影院| 久久久久18| 久久久久久午夜精品| 久久人人青草97香蕉| 国产成人无码精品久久久性色|