How to add an icon to a QTabWidget (not for each t

2019-09-19 16:03发布

I would like to add an icon at the top left of the QTabWidget. I don't want to add an icon for each tab. How to do that using a stylesheet or programmatically in C++?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-09-19 16:49

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.

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 */
}
查看更多
乱世女痞
3楼-- · 2019-09-19 16:50

You can add a first tab with a fixed stylesheet : TabWidget stylesheet example

查看更多
登录 后发表回答