Search code examples
c++qtqtstylesheetsqtabwidget

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. I don't want to add an icon for each tab. How to do that using a stylesheet or programmatically in C++?


Solution

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