Results 1 to 9 of 9

Thread: Menu palette question

  1. #1
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Menu palette question

    Hi,

    First I am new to the qcentre forums and I would like to introduce myself. My name is Susan and am fairly new to Qt4 (I've experience with Qt3); I have been working with it for the last couple of months.

    I am working on a prototype and have to apply custom colors to almost everything. This is really easy to do with ColorRoles, etc. in widget palettes. But I have been stumped when trying to apply a color to a popup or pulldown menu.

    For example, the menu that is displayed when a combo box is activated needs a specific color. I haven't been able to figure out how to do that. When I access the backgroundRole or foregroundRole of the QAbstractItemView (via the ::view() method), it is Window and WindowText respectively, and when set the view's palette (setting these roles to different colors) I get no change in color!

    Any hints on what needs to be done for menus?

    Much appreciated in advance,
    Susan Macchia

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Menu palette question

    Hi, welcome on board!

    Qt Code:
    1. QPalette p = comboBox->view()->palette();
    2. p.setColor(QPalette::Base, Qt::red);
    3. comboBox->view()->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    smacchia (21st February 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs down Re: Menu palette question

    Thank you. Unfortunately that didn't work. Neither did:

    Qt Code:
    1. QAbstractItemView *v = combo->view();
    2. p.setColor(QPalette::Base, Qt::red);
    3. p.setColor(QPalette::Text, Qt::white);
    4. view->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    I see a brief flash of the red only on the selected item. Then it goes back to the default. The menu itself (apart from the selected item) is not affected by the color choice.

    I tried ::setColor with all the roles to no avail...

    Any other pointers?

    Thanks much.
    Susan
    Last edited by smacchia; 21st February 2007 at 19:46.

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Menu palette question

    Oh, you are running GNOME? Seems like it indeed doesn't work with the cleanlooks style.. Stylesheets introduced in 4.2 usually are a solution to palette problems, but even this doesn't work:
    Qt Code:
    1. comboBox->setStyleSheet("QAbstractItemView { background: yellow }");
    To copy to clipboard, switch view to plain text mode 
    Feels like a bug to me..
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    smacchia (21st February 2007)

  7. #5
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menu palette question

    Yes I am running under gnome. The final product will be running without a window manager. I'll see how it works under KDE and study style sheets. I'll report back with my findings.

  8. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Menu palette question

    By the way, you can preview it with another style by passing a cmd line parameter:
    $ ./yourapp -style plastique
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    smacchia (21st February 2007)

  10. #7
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Menu palette question

    Yes I know, though that may not impact the settings under Gnome. I'll experiment a bit more and Thanks for all the help on this!

  11. #8
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Menu palette question

    Under gnome, using the style sheet works; I was able to get it to work programatically using the ::setStyleSheet method and by reading an external .qss file.

    So there is a bug using the palette. I also tried it under ICWM and found the same bug, so it may not be related to the desktop or window manager. Nevertheless, I'll submit a bug to Trolltech on the palette problem.

    Thanks for the pointers, they really helped!

    I am finding that I'll probably need to use a combination of style sheets and palettes because, for example, when you set the color of a QPushButton using the style sheet, you lose the Plastique look & feel (haven't tried it running under another L/F). But it works fine for QToolButton & QComboBox. I also noticed that I wasn't able to set the background color of tables or lists in style sheets either. But I'll continue working with it.
    Last edited by smacchia; 22nd February 2007 at 15:26.

  12. #9
    Join Date
    Feb 2007
    Posts
    73
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Menu palette question - new problem!

    So now I see another issue using the stylesheet for the combo box instead of QPalette. In the plastique style there is a "check" next to the selected item and it shouldn't be there in plastique. How would I make sure the L/F of the widget adheres to the platform style?
    Last edited by smacchia; 26th February 2007 at 20:54.

Similar Threads

  1. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  2. "About app" not getting translated on Mac app menu
    By sharevari in forum Qt Programming
    Replies: 0
    Last Post: 24th January 2007, 16:24
  3. QPalette Question
    By jlgerber in forum Newbie
    Replies: 7
    Last Post: 14th November 2006, 19:19
  4. Qt/MacOSX preferences menu item
    By mcenatie in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2006, 04:24
  5. Tracking separators in a menu (insertSeparator)
    By PrimeCP in forum Qt Programming
    Replies: 4
    Last Post: 25th January 2006, 18:10

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.