Results 1 to 6 of 6

Thread: Styling QMenubar???

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

    Default Styling QMenubar???

    hi all,
    I want to style a Qmenubar. i want to make it transparent i.e it should take the background color of widget in which it is formed.i am using stylesheet for it .but it is not working..
    i used the following code:
    Qt Code:
    1. TabWindow::TabWindow(QWidget *parent): QWidget(parent)
    2. {
    3. menubar=new QMenuBar(this);
    4. fileMenu=new QMenu("File",this);
    5. actionMenu=new QMenu("Actions",this);
    6. menubar->addMenu(fileMenu);
    7. menubar->addMenu(actionMenu);
    8. menubar->setStyleSheet("background-color: transparent");
    9. }
    To copy to clipboard, switch view to plain text mode 
    What to do??

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Styling QMenubar???

    Put your menu bar in the widget layout and it should work. Note that QWidget has by default no space for a QMenuBar like QMainWindow has it!

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

    Default Re: Styling QMenubar???

    thnx for reply,
    I tried this but it does nt work...........
    I used this way
    Qt Code:
    1. Widget::Widget(QWidget *parent): QWidget(parent)
    2. { menubar=new QMenuBar(this);
    3. fileMenu=new QMenu("File",this);
    4. menubar->setGeometry(10,10,40,20);
    5. actionMenu=new QMenu("Actions",this);
    6. menubar->addMenu(fileMenu);
    7. menubar->addMenu(actionMenu);
    8. menubar->setStyleSheet("background-color: red);");
    9. }
    To copy to clipboard, switch view to plain text mode 

    But widget is not showing menubar
    How to do??

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Styling QMenubar???

    You have a typo! Skip the ")".
    Qt Code:
    1. menubar->setStyleSheet("background-color: red;");
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Styling QMenubar???

    I corrected that but still not showing the menubar
    if i skip the line menubar->setStyleSheet("background-color: red;");
    it shows the normal qmenubar.
    what is the problem in setting stylesheet

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Styling QMenubar???

    It's because you have not put the menubar in a layout! If you don't want to do so call
    Qt Code:
    1. menubar->adjustSize();
    To copy to clipboard, switch view to plain text mode 
    then the menu bar is shown. (Skip your geometry line.)

  7. The following user says thank you to Lykurg for this useful post:

    anupamgee (29th April 2009)

Similar Threads

  1. Styling ScrollBar of QWebView via Qt StyleSheets?
    By chuckshaw in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2011, 20:29
  2. Question about "delete" on QMenuBar instance..
    By tgreaves in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2009, 23:10
  3. Hide Qmenubar
    By user_mail07 in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 23:16
  4. QDialog and QMenuBar
    By lutins in forum General Programming
    Replies: 4
    Last Post: 13th September 2008, 15:39
  5. where could QPopupMenu show besides QMenuBar !
    By bigbigmoon in forum Newbie
    Replies: 4
    Last Post: 2nd November 2006, 02:03

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.