Home > Mobile >  Change tab close button to be a custom image?
Change tab close button to be a custom image?

Time:08-02

I have a browser which looks like this:

custom qt py browser

It is working great. However, I want to change that red X next to the tab name to be a nicer icon. Is this possible to change? I couldn't find anything in the documentation.

CodePudding user response:

As mentioned in the comments you can use QStyleSheets which is the easiest way.

QTabBar::close-button {
    image: url(close.png)
    subcontrol-position: left;
}
QTabBar::close-button:hover {
    image: url(close-hover.png)
}

Or if you wanted to customize each tab, or wanted more control over what the button does you could create QToolButton connect it to an action and then assign it to a tab with the QTabBar.setTabButton method.

tab_bar.setTabButton(0, QTabBar.ButtonPosition.RightSide, close_btn)
  • Related