QT:我继承自QTreeView。我继承自 QStandardItem。我如何设计项目?
今天我的 Google 技能肯定让我失望了。
我继承了 QTreeView 来创建一个存储 QStandardItemModel 而不是 QAbstractItemModel 的 TreeView。我还继承了 QStandardItem 来创建一个类来根据需要将我的数据存储在项目中。
我已成功将派生的 QStandardItem 插入派生的 QTreeView 的 QStandardItemModel 中。现在的问题是,我不知道如何设计它。我知道 QTreeView 有一个 setStyleSheet(QString) 成员,但我似乎无法让它工作。这可能很简单,因为我没有设置正确的属性样式。任何指示将不胜感激。谢谢。
为了清楚起见,这是我的类定义。
class SurveyTreeItem : public QStandardItem { public: SurveyTreeItem(); SurveyTreeItem( const QString & text ); ~SurveyTreeItem(); }; class StandardItemModelTreeView : public QTreeView { public: StandardItemModelTreeView(QWidget* parent = 0); ~StandardItemModelTreeView(); QStandardItemModel* getStandardItemModel(); };
我尝试过以下样式表:
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::SurveyTreeItem { font: 87 12pt 'Arial Black'; }
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::SurveyTreeItem { font: 87 12pt 'Arial Black'; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎已经拥有了 QTreeView::item 应该就是这个。为 Qt 样式表参考添加书签。如果您正在做这种事情,整个部分是一个很好的阅读。
QTreeView
内容的字体应该通过QTreeview
本身设置样式,例如QTreeview {font-size: 20pt;}
而不是通过项目的样式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 theQTreeview
itself e.g.QTreeview {font-size: 20pt;}
and not via the style of the item