• <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編程
             
            久久精品免费一区二区| 77777亚洲午夜久久多喷| 2020久久精品亚洲热综合一本| 中文字幕乱码人妻无码久久| 99久久久精品免费观看国产| 亚洲国产一成久久精品国产成人综合 | 伊人久久综合精品无码AV专区| 久久久久久毛片免费播放| 久久久久国产一区二区| 国产精品国色综合久久| 中文字幕久久亚洲一区| 国产精品免费久久久久电影网| 人妻少妇久久中文字幕| 久久精品成人影院| 91性高湖久久久久| 久久国产亚洲高清观看| 久久精品国产久精国产一老狼| 久久九九久精品国产| 99久久夜色精品国产网站| 97久久香蕉国产线看观看| 亚洲成色WWW久久网站| 人人妻久久人人澡人人爽人人精品| 国产精品日韩欧美久久综合| 久久99亚洲网美利坚合众国| 性高湖久久久久久久久| 久久久久久久久久久| 91麻豆国产精品91久久久| 久久久久久国产精品无码下载| 品成人欧美大片久久国产欧美| 成人妇女免费播放久久久| 欧美噜噜久久久XXX| 亚洲精品蜜桃久久久久久| 一本色道久久88—综合亚洲精品| 亚洲天堂久久久| 久久人妻AV中文字幕| 免费精品久久天干天干| 久久天天躁狠狠躁夜夜avapp| 色狠狠久久综合网| 久久精品青青草原伊人| 久久丫精品国产亚洲av不卡| 99久久无码一区人妻a黑|