• <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>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            In order to change the color of the items in the model you need to reimplement the data function and return the colors you want for theQt::BackgroundColorRole or the Qt::TextColorRole roles. See the documentation:

            http://doc.trolltech.com/4.3/qabstractitemmodel.html#data

            http://doc.trolltech.com/4.3/qt.html#ItemDataRole-enum

            The example below demonstrates how this can be achieved.

            Note that you can also reimplement the QItemDelegate::paint() in order to change the color the items in a view. See the following FAQ:

            http://trolltech.com/developer/knowledgebase/faq.2007-11-21.7774969370/

            #include <QtGui>
            
            class ColorModel : public QAbstractTableModel
            {
            public:
                ColorModel(QObject *parent) 
                {
                    QStringList firstRow;
                    QStringList secondRow;
            
                    for (int i = 0; i < 5; i++ ) {
                        firstRow.insert(i,"Row " + QString::number(i+1));
                    }
                    for (int i = 0; i < 5; i++ ) {
                        secondRow.insert(i,"Row " + QString::number(i+1));
                    }
            
                    stringList << firstRow << secondRow;
                }
            
                // Returns the number of rows
                int rowCount ( const QModelIndex & parent = QModelIndex() ) const
                {
                    return 2;
                }
            
                // Returns the number of columns
            
                int columnCount ( const QModelIndex & parent = QModelIndex() ) const
                {
                    return 5;
                }
            
                // Returns an appropriate value for the requested data.
                // If the view requests an invalid index or if the role is not
                // Qt::DisplayRole, Qt::BackgroundColorRole or QTextColorRole, an invalid variant is returned.
                // Any valid index that corresponds to a string for the index's column and row in
                // the stringlist is returned for the Qt::DisplayRole
            
                QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const 
                {
                    if (!index.isValid())
                        return QVariant();
            
                    if (role == Qt::BackgroundRole) {
                        if (index.row() == 0)
                            return QColor(Qt::blue);
                        else
                            return QColor(Qt::white);
                    } else if (role == Qt::DisplayRole) {
                        QStringList list = (QStringList)stringList.at(index.row());
                        return list.at(index.column());
                    } else if (role == Qt::ForegroundRole ) {
                        if (index.row() == 1)
                            return QColor(Qt::red);
                    } 
            
                    return QVariant();
                }
            
            private: 
                // Each row will consist of a list of strings
                QList<QStringList>stringList;
            };
            
            int main(int argc, char **argv)
            {
                QApplication app(argc, argv);
                QWidget widget;
            
                QHBoxLayout *layout = new QHBoxLayout(&widget);
                QTreeView *treeView = new QTreeView(&widget);
                QTableView *tableView = new QTableView(&widget);
                ColorModel *model = new ColorModel(tableView);
                tableView->setModel(model);
                treeView->setModel(model);
                layout->addWidget(treeView);
                layout->addWidget(tableView);
                widget.show();
                return app.exec(); 
            }
            posted on 2009-05-18 17:26 逛奔的蝸牛 閱讀(846) 評論(0)  編輯 收藏 引用 所屬分類: Qt
            亚洲伊人久久综合影院| 国产成人综合久久综合| 亚洲AV无码久久| 久久精品无码一区二区无码| 99久久99久久精品免费看蜜桃| 久久这里只有精品18| 国内精品久久久久久久久电影网| 久久综合久久鬼色| 国产成人久久精品区一区二区| 久久综合久久综合九色| 日本精品久久久久影院日本| 国产精品免费福利久久| 久久综合视频网| 国产一级持黄大片99久久| 精品伊人久久大线蕉色首页| 久久天天躁狠狠躁夜夜2020老熟妇| 久久久久亚洲AV无码专区首JN | 久久久噜噜噜久久中文字幕色伊伊| 午夜视频久久久久一区 | 国内精品久久久久影院网站| 精品多毛少妇人妻AV免费久久| 精品多毛少妇人妻AV免费久久| 色8久久人人97超碰香蕉987| 久久久久久av无码免费看大片| 7777久久亚洲中文字幕| 久久这里的只有是精品23| 99久久99久久| 九九久久自然熟的香蕉图片| 欧美亚洲国产精品久久| 超级碰碰碰碰97久久久久| 亚洲一区二区三区日本久久九| 日本一区精品久久久久影院| 日韩久久久久久中文人妻| 久久笫一福利免费导航| 久久强奷乱码老熟女网站| 国产福利电影一区二区三区,免费久久久久久久精 | 88久久精品无码一区二区毛片| 久久成人国产精品免费软件| 亚洲AⅤ优女AV综合久久久| 久久精品无码一区二区三区日韩| 久久免费国产精品一区二区|