Reputation: 174
In Qt and C++, is it possible to place a QWidget next to the tabs of a QTabWidget?
To clarify what I mean the following picture:
The red rectangle in this picture belongs to QTabWidget, but is not used because all the tabs are small enough to not need it. Would it be possible to place another QWidget here?
Upvotes: 1
Views: 526
Reputation: 4881
QTabWidget
is easy-to-use combination of a QTabBar
and a QStackedWidget
.
So instead of using QTabWidget
, you can use QTabBar
and QStackedWidget
directly. Just connect the QTabBar::currentChanged
signal to the QStackedWidget::setCurrentIndex
slot and you'll get the same functionality. The advantage is that you can place the two freely on your form. You can place them in a grid layout and place any additional widgets next to the QTabBar
.
Upvotes: 5
Reputation: 3
I used following stylesheet when I combined QTabBar
with QStackedWidget
. However, it is missing the border. I didn't know how to style the top of the page just under the bar (without the border appearing under selected tab).
QTabBar::tab {
padding: 5px 10px 5px 10px;
}
QTabBar::tab:selected {
background-color: white;
}
QTabBar::tab:!selected {
border-bottom: 1px solid rgb(240, 240, 240); \
background-color: rgb(240, 240, 240);
}
QStackedWidget {
background-color: white;
}
Upvotes: 0