PDA

View Full Version : QToolBar setstylesheet Problem



sudheer168
3rd June 2010, 09:27
Hi every one ,

I am using QT4.4.3 under windows XP . I am trying to change the style of toolbar of mainwindow that mean I am trying to change the color of the tool bar , but i am not able to do it . The code I tried is




QToolBar *fileToolBar = new QToolBar(this);
fileToolBar ->setStyleSheet("QToolBar{background:gray;}");



So please suggest me how to change the style of the tool bar so that i can set my own color or gradient .


Regards
Sudheer.

aamer4yu
3rd June 2010, 11:02
It works fine for me.. you must have overriden something.

muro345
15th July 2010, 16:04
got the same problem, using qt4.4.6.2 at ubuntu 10.04 linux 2.6.32-22.37



QToolBar* mainToolBar;

...

mainToolBar = new QToolBar(this);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
mainToolBar->setStyleSheet("QToolBar { background:red; }");
mainToolBar->setMovable(false);
mainToolBar->setAllowedAreas(Qt::TopToolBarArea);
mainToolBar->setIconSize(QSize(56, 56));
mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
mainToolBar->setFont(font);
...



but the bar is still light-grey (default)

muro345
20th July 2010, 12:57
i solved the toolbar problem like this:


QToolBar#myToolBar > QWidget {
background: blue;
}

if i do this:

QToolBar#myToolBar {
background: blue;
}
only the action buttons get colored.

i got some other problems with style though.
problem appears if I use my own class inherited from QWidget


class my_widget_class : public QWidget
{
Q_OBJECT

public:
my_widget_class(QWidget* );
QListView * listView;
void mouseMoveEvent(QMouseEvent* pEvent);

};

implementation looks like this:


my_widget_class* my_widget;

/* some ui code here */

my_widget = new my_widget_class (centralWidget);
my_widget->setObjectName("my_widget_00");
my_widget->setGeometry(QRect(100,100,100,200));

the style sheet is like this:


my_widget_classt#my_widget_00 {
background-color: blue;
border-style: outset;
border-width: 2px;
border-radius: 20px;
border-color: red;
font: bold 14px;
min-width: 10em;
padding: 6px;
}

i also tried style with QWidget#my_widget

it works if i replace my_widget_class with QWidget in the code (like: "my_widget = new QWidget(centralWidget);" )
is this a normal behaviour? i think it should recognise my new class as QWidget...
i use the same method for my main window class, but this works fine.