Results 1 to 4 of 4

Thread: QToolBar setstylesheet Problem

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QToolBar setstylesheet Problem

    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

    Qt Code:
    1. QToolBar *fileToolBar = new QToolBar(this);
    2. fileToolBar ->setStyleSheet("QToolBar{background:gray;}");
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QToolBar setstylesheet Problem

    It works fine for me.. you must have overriden something.

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToolBar setstylesheet Problem

    got the same problem, using qt4.4.6.2 at ubuntu 10.04 linux 2.6.32-22.37

    Qt Code:
    1. QToolBar* mainToolBar;
    2.  
    3. ...
    4.  
    5. mainToolBar = new QToolBar(this);
    6. mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
    7. mainToolBar->setStyleSheet("QToolBar { background:red; }");
    8. mainToolBar->setMovable(false);
    9. mainToolBar->setAllowedAreas(Qt::TopToolBarArea);
    10. mainToolBar->setIconSize(QSize(56, 56));
    11. mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    12. mainToolBar->setFont(font);
    13. ...
    To copy to clipboard, switch view to plain text mode 

    but the bar is still light-grey (default)

  4. #4
    Join Date
    Jul 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QToolBar setstylesheet Problem

    i solved the toolbar problem like this:
    Qt Code:
    1. QToolBar#myToolBar > QWidget {
    2. background: blue;
    3. }
    To copy to clipboard, switch view to plain text mode 
    if i do this:
    Qt Code:
    1. QToolBar#myToolBar {
    2. background: blue;
    3. }
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. class my_widget_class : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. my_widget_class(QWidget* );
    7. QListView * listView;
    8. void mouseMoveEvent(QMouseEvent* pEvent);
    9.  
    10. };
    To copy to clipboard, switch view to plain text mode 
    implementation looks like this:
    Qt Code:
    1. my_widget_class* my_widget;
    2.  
    3. /* some ui code here */
    4.  
    5. my_widget = new my_widget_class (centralWidget);
    6. my_widget->setObjectName("my_widget_00");
    7. my_widget->setGeometry(QRect(100,100,100,200));
    To copy to clipboard, switch view to plain text mode 
    the style sheet is like this:
    Qt Code:
    1. my_widget_classt#my_widget_00 {
    2. background-color: blue;
    3. border-style: outset;
    4. border-width: 2px;
    5. border-radius: 20px;
    6. border-color: red;
    7. font: bold 14px;
    8. min-width: 10em;
    9. padding: 6px;
    10. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by muro345; 20th July 2010 at 12:04.

Similar Threads

  1. In the QTimer Slot, the setStyleSheet Problem
    By nightrain in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2009, 10:39
  2. problem in QProgressBar setStyleSheet
    By wagmare in forum Qt Programming
    Replies: 3
    Last Post: 27th April 2009, 09:03
  3. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 06:57
  4. using setStyleSheet
    By Weilor in forum Qt Programming
    Replies: 11
    Last Post: 18th January 2008, 13:41
  5. QSpinBox and setStylesheet problem
    By Ace-X in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 11:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.