• <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>
            隨筆 - 70, 文章 - 0, 評(píng)論 - 9, 引用 - 0
            數(shù)據(jù)加載中……

            QTableView, QTableWidget 用法整理

            1  根據(jù)數(shù)據(jù)內(nèi)容設(shè)定寬
                resizeColumnToContents, resizeColumnsToContents
            void QTableView::resizeColumnToContents ( int column ) [slot]
            void QTableView::resizeColumnsToContents () [slot]

            2  去掉網(wǎng)格 setShowGrid

            3  委托
                需要在單元格里進(jìn)行特別處理,如需要QLineEdit, QComcoBox等時(shí),需要用委托機(jī)制來(lái)實(shí)現(xiàn)。
                委托需要實(shí)現(xiàn)的幾個(gè)函數(shù)
                QTableView, QTableWidget對(duì)其數(shù)據(jù)進(jìn)行委托:setItemDelegate, setItemDelegateForColumn, setItemDelegateForRow
                委托時(shí)QItemDelegate需要重新實(shí)現(xiàn)的函數(shù):createEditor(創(chuàng)建控件),setEditorData(設(shè)置值),setModelData,updateEditorGeometry(設(shè)置大小)
                部分實(shí)現(xiàn)代碼示例
            QWidget *LLineEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
            {
                QLineEdit 
            *editor = new CompleteLineEdit(parent);
                
            return editor;
            }


            void LLineEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
            {
                QString value 
            = index.model()->data(index, Qt::EditRole).toString();
                QLineEdit 
            *lineEdit = static_cast<QLineEdit *>(editor);
                lineEdit
            ->setText(value);
            }


            void LLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
            {
                QLineEdit 
            *lineEdit = static_cast<QLineEdit *>(editor);
                QString value 
            = lineEdit->text();
                model
            ->setData(index, value, Qt::EditRole);
            }


            void LLineEditDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
            {
                editor
            ->setGeometry(option.rect);
            }

            posted on 2011-03-24 09:58 seahouse 閱讀(5616) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Qt

            99久久成人国产精品免费 | 日韩乱码人妻无码中文字幕久久 | 精品久久久久久无码国产| 亚洲Av无码国产情品久久| 人妻少妇精品久久| 成人综合久久精品色婷婷| 久久人人爽人人爽人人片av麻烦| 国产精品99久久久精品无码| 国产精品欧美久久久久天天影视| 久久婷婷国产剧情内射白浆| 九九精品99久久久香蕉| 久久久久av无码免费网| 久久久久久久久久久久久久| 久久久久亚洲av成人无码电影| 久久A级毛片免费观看| 亚洲国产天堂久久综合| 久久精品国产一区二区| 久久无码AV中文出轨人妻 | 久久国产精品成人免费| 午夜人妻久久久久久久久| 亚洲国产小视频精品久久久三级| 久久国产精品一区| 欧美性大战久久久久久| 久久精品无码一区二区三区免费| 7777精品伊人久久久大香线蕉| 激情久久久久久久久久| 久久亚洲国产成人精品无码区| 三级韩国一区久久二区综合| 色妞色综合久久夜夜| 久久精品国产亚洲AV无码偷窥| 99热都是精品久久久久久| 伊人久久无码精品中文字幕| 国产精品美女久久久久久2018| 97精品国产91久久久久久| 99久久国产亚洲综合精品| 久久久久中文字幕| 久久精品女人天堂AV麻| 欧美黑人又粗又大久久久| 久久嫩草影院免费看夜色| 久久96国产精品久久久| 中文字幕人妻色偷偷久久|