How to change color of Tab in QTabWidget? and how to change shape of TAB, the shape other than available in Qt.
How to change color of Tab in QTabWidget? and how to change shape of TAB, the shape other than available in Qt.
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
You will need to subclass QTabWidget and QTabBar. In the reimplemented version of QTabBar you can changed the color of any tab.
Use the protected function - setTabBar() of QTabWidget to set your custom tab.
Mithin
www.mithin.in
If you want to change the colour of all tabs to the same value, you can avoid subclassing and just change the palette of the tab bar. To change the shape, you have to reimplement the paint event and do the drawing yourself.
changing palette not chnaging color
see the code after subclassing
TabWidget::TabWidget(QWidget *parent): QTabWidget(parent),mousePressFlag(false)
{
bar=tabBar();
QPalette palette;
bar->installEventFilter(this);
palette.setColor(QPalette::Active,QPalette::Button ,QColor(0,0,255));
bar->setPalette(palette);
bar->setAutoFillBackground(true);
};
see the trolltech reply:
> 1. How to change color of Tab in QTabWidget?
You can subclassing the style you are using and re-implement
drawControl() function. In this function you could fill the rectangle
that the tab covers and then call drawControl() function from the base
class.
how to do this? any idea?
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
I would try something like:Originally Posted by rajesh
Qt Code:
tabBar()->setPalette(pal); }To copy to clipboard, switch view to plain text mode
Subclass one of QStyle subclasses, reimplement drawControl() by changing the colour palette used for drawing the control and force that style on your application. But I think it might be easier to subclass QTabBar as already suggested.see the trolltech reply:
> 1. How to change color of Tab in QTabWidget?
You can subclassing the style you are using and re-implement
drawControl() function. In this function you could fill the rectangle
that the tab covers and then call drawControl() function from the base
class.
how to do this? any idea?
Qt Code:
{ tabBar()->setPalette(pal); }To copy to clipboard, switch view to plain text mode
not working
Last edited by jacek; 17th July 2006 at 12:58. Reason: changed [ html ] tags to [ code ] tags
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
I think QWindowsXPStyle might not respect the palette.
Even setting red palette (for each and every color role) to a tab widget:
Only tab bar background gets red color, see the attached screenshot.Qt Code:
To copy to clipboard, switch view to plain text mode
J-P Nurmi
This:
Qt Code:
#include <QApplication> #include <QTabWidget> #include <QPalette> #include <QTabBar> public: tabBar()->setPalette(pal); } }; int main(int argc, char **argv){ MyTabWidget tw; tw.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
gives the result illustrated by the attachment on Plastique. Run it with -style <stylename> to check other styles, if you want.
I created project using qmake -tp vc xxx.pro
and compling using VC++ on windows xp.
so, hot to set -style <stylename> ?
wysota code changing only text color.
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
Run it from the command line and give it the above mentioned parameter, like:Originally Posted by rajesh
xxx.exe -style plastique
Not only (inactive tabs are coloured and active one has a yellow border), but the point is it doesn't work like expected. It probably takes the tab colour from the main widget associated with the tab, so you might try to change the colour of that and see if the tab changes too.wysota code changing only text color.
It's not working for me!!!
Bookmarks