开发者

QT: I've inherited from QTreeView. I've inherited from QStandardItem. How do i Style the items?

开发者 https://www.devze.com 2022-12-26 01:35 出处:网络
My Google skills must be failing me today. I\'ve inherited from QTreeView to create a TreeView that stores a QStandardItemModel instead of a QAbstractItemModel. I have also inherited from QStandardIt

My Google skills must be failing me today.

I've inherited from QTreeView to create a TreeView that stores a QStandardItemModel instead of a QAbstractItemModel. I have also inherited from QStandardItem to create a class to store my data in an item as is necessary.

I've successfully inserted my derived QStandardItem into my derived QTreeView's QStandardItemModel. Now the trouble is, I can't figure out how to style it. I know that QTreeView has a setStyleSheet(QString) member, but I can't seem to get it working. It may be as simple as I'm not styling the correct attribute. Any pointers would be appreciated. Thanks.

For clarity, here are my class defs.

class SurveyTreeItem : public QStandardItem
{
public:
    SurveyTreeItem();
    SurveyTreeItem( const QString & text );
    ~SurveyTreeItem();
};

class StandardItemModelTreeView : public QTreeView
{
    public:

    StandardItemModelTreeView(QWidget* parent = 0);
    ~StandardItemModelTreeView();

    QStandardItemModel* getStandardItemModel();
};

I've tried the following StyleSheets:

StandardTreeView::Item
{
font: 87 12pt 'Arial Black';
}

StandardTreeView::QStandardItem
{
font: 87 12pt 'Arial Black';
}

QTreeView::QStandardItem
{
font: 87 12pt 'Arial Black';
}

QTreeView::Item
{
font: 87 12pt 'Arial Black';
}

QTreeView::SurveyTreeItem
{
font: 87 12pt 'Arial Black';
}

StandardTreeView::SurveyTreeI开发者_如何学Gotem
{
font: 87 12pt 'Arial Black';
}


You almost had it QTreeView::item should be the one. Bookmark Qt Style Sheets Reference. That whole section is a pretty good read if you are doing this sort of thing

The font of the content of a QTreeView should be styled via the QTreeview itself e.g. QTreeview {font-size: 20pt;} and not via the style of the item

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号