Tab close button position

EDIT : I know this post is old, but I hope it could help someone else.

After a couple of tests, I think there is one way to do this, but it does not use Qt style sheets :

  1. Subclass your QTabWidget to have complete access to the protected features
  2. Create your own QWidget or QPushButton as your close button
  3. Manage the position of your button with the stylesheet property (margin-right for example)
  4. 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)
{
/// Create your button
QPushButton *close = new QPushButton(this);

// Add a tab
addTab(new QWidget(), QIcon(), "Tab 1");
setStyleSheet("QTabBar::tab { width : 150px;}");

// Size and move your button
close->setStyleSheet("max-height: 14px; max-width: 15px; margin-right: 50px;");

// Add your button to the tab
tabBar()->setTabButton(0, QTabBar::RightSide, close);
}

Finally, in the MainWindow, I added my own TabWidget to a layout :

ui->layout->addWidget(new MyTab(this));

The result :

enter image description here

But now you will have to handle the close action manually by connecting the button and get the index for a removeTab(index) call.