EDIT: I know this post is outdated, but I hope this can help someone else.
After several tests, I think there is one way to do this, but it does not use Qt style sheets :
- The
QTabWidget subclass must have full access to protected functions. - Create your own
QWidget or QPushButton as a close button. - Controlling the position of your button using the stylesheet property (e.g.
margin-right ) - Add your button to the tab
tabBar()->setTabButton(index, QTabBar::RightSide, closeButton);
The code I used for the test:
MyTab::MyTab(QWidget *parent) : QTabWidget(parent) {
Finally, in MainWindow, I added my own TabWidget to the layout:
ui->layout->addWidget(new MyTab(this));
Result:

But now you have to handle the closing action manually by connecting the button and getting the index to call removeTab(index) .
source share