How to change cornerWidget style in QTabWidget?
-
Desired result: all buttons should have same height and margins from top and bottom. Tool button margins from left and right could be changes when tool button is inserted into container widget with QHBoxLayout. More precisely, I'd like to change size/margins of tool button, not scroll buttons.
-
@Eugene-Zelenko
Hi
You can set a minimum size to it
list_tool_button_->setMinimumSize(32,64);
but its different pr platform so not sure its what you want. -
@mrjj said in How to change cornerWidget style in QTabWidget?:
list_tool_button_->setMinimumSize(32,64);
I tried this. Button was enlarged, but misaligned.
My application also has command-line option to set
QT_SCALE_FACTOR
, so fixed size is not best solution.Does
QTabWidget
has style options that affect corner widgets? -
@Eugene-Zelenko said in How to change cornerWidget style in QTabWidget?:
Does QTabWidget has style options that affect corner widgets?
Not that i have seen. basically its just a widget.
-
Internally the corner widgets get the correct geometry. I guess it's due to the fact that the QToolButton has size constraints. Try to set them to expanding.
-
No, changing vertical size policy to expanding didn't help.
Probably changing QTabWidget::initStyleOption could help, but method is not virtual :-(
-
@Eugene-Zelenko said in How to change cornerWidget style in QTabWidget?:
No, changing vertical size policy to expanding didn't help.
Maybe there is a min/max size on it. First try to use a simple QWidget or QLabel to see if it expands correctly.
-
I tried to create
QLineEdit
, because it's more noticeable an it behave similar toQToolButton
:Code is:
auto* line_edit = new QLineEdit(this); line_edit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding)); line_edit->setText(tr("Test")); line_edit->setMinimumHeight(tabBar()->height() - 2); setCornerWidget(line_edit, Qt::TopRightCorner);
-
I was able to get result very close to what I wanted to 1 pixel from bottom:
Code is:
auto* container = new QWidget(this); container->setFixedHeight(tabBar()->height()); container->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); auto* layout = new QHBoxLayout(container); layout->setContentsMargins(1, 0, 1, 0); list_tool_button_ = new QToolButton(this); list_tool_button_->setFixedHeight(tabBar()->height()); list_tool_button_->setIcon(QIcon(":/images/resources/tabs_list.png")); list_tool_button_->setPopupMode(QToolButton::InstantPopup); list_tool_button_->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); list_tool_button_->setToolButtonStyle(Qt::ToolButtonIconOnly); layout->addWidget(list_tool_button_); setCornerWidget(container, Qt::TopRightCorner);