• <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 閱讀(5588) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Qt

            久久天天躁夜夜躁狠狠| 精品久久久久久无码免费| 久久天天躁狠狠躁夜夜2020老熟妇| 久久偷看各类wc女厕嘘嘘| 伊人久久大香线焦AV综合影院| 99久久精品免费看国产一区二区三区| 久久久久国产成人精品亚洲午夜| 久久se精品一区精品二区国产| 亚洲国产精品久久66| 9191精品国产免费久久| 狠狠色伊人久久精品综合网| 久久久免费观成人影院| 日韩一区二区三区视频久久| 思思久久99热只有频精品66| 久久久一本精品99久久精品88| 久久精品中文无码资源站| 亚洲AV无码久久精品狠狠爱浪潮| 久久超乳爆乳中文字幕| 国产成人精品久久一区二区三区av | 思思久久99热免费精品6| 久久亚洲视频| AV无码久久久久不卡蜜桃| 精品久久久久久成人AV| 青青草国产精品久久| 要久久爱在线免费观看| 亚洲AV日韩AV永久无码久久| 亚洲国产精品一区二区久久| 久久久久久久91精品免费观看| 人妻精品久久久久中文字幕69| 一级做a爱片久久毛片| 久久人人超碰精品CAOPOREN| 欧美黑人又粗又大久久久| 久久九九青青国产精品| 人人妻久久人人澡人人爽人人精品| av无码久久久久久不卡网站| 欧美成a人片免费看久久| 久久久久久国产精品无码超碰 | 情人伊人久久综合亚洲| 国产亚洲美女精品久久久2020| 久久精品国产亚洲麻豆| 99久久精品免费看国产一区二区三区 |