• <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久国产麻精品66| 精品欧美一区二区三区久久久 | 人妻丰满?V无码久久不卡| 中文成人久久久久影院免费观看| 久久天堂AV综合合色蜜桃网| 精品午夜久久福利大片| 久久99热这里只有精品66| 久久久久久噜噜精品免费直播| 国产精品欧美久久久久天天影视 | 漂亮人妻被黑人久久精品| 狠狠色婷婷久久综合频道日韩 | 欧美一区二区精品久久| 99久久精品国产毛片| 精品久久久久久无码中文字幕 | 国产精品99久久精品| 久久精品国产半推半就| 久久精品国产亚洲Aⅴ香蕉| 亚洲精品午夜国产va久久| 日本人妻丰满熟妇久久久久久| 国产精品久久久久天天影视| segui久久国产精品| 99久久99久久久精品齐齐 | 久久人妻少妇嫩草AV无码蜜桃| 亚洲国产精品无码久久| 亚洲国产日韩欧美久久| a级毛片无码兔费真人久久| 狠狠色丁香久久综合五月| 色欲综合久久躁天天躁蜜桃| 欧美国产成人久久精品| 久久涩综合| 久久精品综合一区二区三区| 久久九九有精品国产23百花影院| 久久久噜噜噜久久熟女AA片 | 日韩欧美亚洲综合久久影院Ds| 国产成人综合久久久久久| 国产精品美女久久久久网| 久久精品国产第一区二区三区 | 亚洲午夜久久久久久噜噜噜| 天天影视色香欲综合久久| 欧美粉嫩小泬久久久久久久| 色综合久久天天综线观看|