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

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

我想在 QTabWidget 的左上角添加一个图标。我不想为每个选项卡添加一个图标。如何使用样式表或在 C++ 中以编程方式做到这一点?

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

下面的样式表会将图像添加到所有选项卡的左侧,但不会添加到单个选项卡。但是,您很可能需要调整 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 */
}