I'm using Qt and I have a QTabWidget setup in the Qt Designer Editor, you can see it in picture 1.
picture 1 http://i40.tinypic.com/1109ba1.jpg
As you can see after Tab4 there is an empty space all the way to the right edge, in someway I need to fill that space with a color, like in picture 2 (the best thing would be to be able to set a fading color). Or another solution would be that the tabs float out to cover the whole screen.
picture 2 http://i41.tinypic.com/zwmijr.jpg
I use the following stylesheet right now:
QTabWidget::tab-bar {
}
QTabBar::tab {
background: gray;
color: white;
padding: 10px;
}
QTabBar::tab:selected {
background: lightgray;
}
Is there a way to set the background color of the QTabBar using Qt stylesheets? Or can I get the tabs floating out to the edge using Qt stylesheets?
EDIT: I have been trying the solution that Caleb Huitt - cjhuitt suggested below. I really like the idea of making the tabs expand but can't get it working.
In Qt Designer Editor I right click on my QTabWidget->"Promote To ..." and choose "Base class name": QTabWidget "Promoted class name": ExpandableTabWidget and then I click add and then Promote.
In the init method of the widget that holds my QTabWidget I set
ui.tabWidget->SetTabsExpanding(true);
Everything is building fine but the QTabbar doesn't expand.
Am I doing something wrong?
Thanks!
Both expanding tabs and coloring the background can be accomplished using style sheets.
For expanding tabs, a style sheet can be applied to the tabs which sets their width to a fraction of the total width of the
QTabWidget
. Since the style sheet will need to be updated upon resize, it is applied using an event filter. See first example code below.Although the background of the tab bar can be set, the tab bar doesn't fill the entire space above the tab pane. It is the container (or parent widget) which is showing through. To control the coloring of that area, put the
QTabWidget
in aQWidget
and set the style sheet on the container. See second example code below.Expanding tabs:
Background beside tabs:
On qt 4.5 there is a new property that control the tab widget rendering, called documentMode. Just call
tabWidget->setDocumentMode(true)
and set the background color of the QTabBar using the stylesheets.From Qt Documentation:
As I see it, you have two options, depending on what you want to do.
To fill the background with color:
Take advantage of the transparency of that portion of the tab widget.
This makes the bg widget all orange, but since most of the tab widget will draw over the bg widget, you'll only see the orange where the tab widget doesn't draw.
To make the tabs expand:
I thought this would be easier than it is, but you basically have to subclass QTabWidget in order to get access to the tab bar widget it uses.
You would then either need to make your
ExpandableTabWidget
class into a plugin and use it in designer, or you could promote your tab widget to be of typeExpandableTabWidget
and set the expanding value in code. If you choose to do the promotion, you won't see the results you want in designer, but you will when you run your program.I had same problem some time ago. I achieved it by making "big" top border, and moving tab bar with margin