Customizing QToolBox: tab height

2019-08-27 02:59发布

问题:

Is there any way to change the height of the tabs on a QToolBox widget and center the title?

I am able to change the height by setting tabSpacing, but then the title is not centered (it is top-aligned). I tried changing the alignment with the stylesheet but no luck. I also tried to force the height with:

QToolBox::tab {
     height: 48px;
     alignment: center;"
     margin: 0px 0px 0px 0px;"
}

BUt it is not working either. Any ideas?

回答1:

After speaking with Qt support, the only way I found was to assign an empty icon to all tabs, and set the icon-size to the desired height.

...
for (int i = 0; i < ui->toolBox->count(); i++){
    ui->toolBox->setItemIcon( i, QIcon(":/shared/empty"));
}
ui->toolBox->setStyleSheet("QToolBox{ icon-size: 48px; }");
...