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

喜欢而已 提交于 2019-12-25 18:46:10

问题


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++?


回答1:


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 */
}



回答2:


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



来源:https://stackoverflow.com/questions/43785389/how-to-add-an-icon-to-a-qtabwidget-not-for-each-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!