简体   繁体   English

如何将图标添加到 QTabWidget(不是每个选项卡)?

[英]How to add an icon to a QTabWidget (not for each tab)?

I would like to add an icon at the top left of the QTabWidget .我想在QTabWidget左上角添加一个图标。 I don't want to add an icon for each tab.我不想为每个选项卡添加图标。 How to do that using a stylesheet or programmatically in C++?如何使用样式表或在 C++ 中以编程方式做到这一点?

Stylesheet below will add an image to the left of all tabs, but not to individual tabs.下面的样式表将在所有选项卡的左侧添加图像,但不会添加到单个选项卡。 However, it is very likely that you'll need to tweak other attributes in the CSS to polish the final result.但是,您很可能需要调整 CSS 中的其他属性来完善最终结果。

QTabWidget > QTabBar {
  background: url(url-to-your-corner-image);
  background-repeat: norepeat;
  margin-top: 10px; /* whatever needed to center the image vertically */
}
QTabWidget > QTabBar::tab:first {
  margin-left: 10px; /* at least the width of your image */
}

您可以添加带有固定样式表的第一个选项卡: TabWidget 样式表示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM