Results 1 to 4 of 4

Thread: how to change background color of QMenu??

  1. #1
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default how to change background color of QMenu??

    hi all,
    i want to change the background color of Qmenu.
    i tried the following code:
    Qt Code:
    1. TabWindow::TabWindow(QWidget *parent) : QWidget(parent)
    2. {
    3. QMenu *menu=new QMenu(this);
    4. onlineAct = new QAction(tr("Online"), this);
    5. busyAct = new QAction(tr("Busy"), this);
    6. menu->addAction(onlineAct);
    7. menu->addAction(busyAct);
    8. connect(onlineAct,SIGNAL(triggered()),this,SLOT(online()));
    9. connect(busyAct,SIGNAL(triggered()),this,SLOT(busy()));
    10. menu->setAutoFillBackground(true);
    11. QPalette palette=menu->palette();
    12. palette.setColor(QPalette::Window, Qt::blue);
    13. menu->setPalette(palette);
    14. }
    To copy to clipboard, switch view to plain text mode 
    but the color is not changing.It is showing white background color.
    what to do??

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to change background color of QMenu??

    have a look at this examples.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Posts
    58
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to change background color of QMenu??

    thnx for reply,
    i am new in qt.Can you plz tell with an example how to use that ?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to change background color of QMenu??

    you can set style sheet using this method QWidget::setStyleSheet.
    so, in you case you should write something like this
    Qt Code:
    1. TabWindow::TabWindow(QWidget *parent) : QWidget(parent)
    2. {
    3. QMenu *menu=new QMenu(this);
    4. menu->setStyleSheet(...);
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. The following user says thank you to spirit for this useful post:

    anupamgee (28th April 2009)

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. How to change Icon size in QMenu?
    By alex chpenst in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2008, 14:16
  4. how to change QTextEdit background color ?
    By mismael85 in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2008, 22:05
  5. Trying to change the background of a QTreeWidget
    By vycke in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 20:44

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.