Results 1 to 6 of 6

Thread: Stylesheet for ActionsContextMenu - how to?

  1. #1
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Stylesheet for ActionsContextMenu - how to?

    I have QTreeView with custom background color. When I add ActionsContextMenu via
    ui.view->setContextMenuPolicy(Qt::ActionsContextMenu); the background of the pop-up window is the same as in background color of treeview.

    Question: how to set up background color of actioncontextmenu?

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Stylesheet for ActionsContextMenu - how to?

    Quote Originally Posted by QPlace View Post
    Question: how to set up background color of actioncontextmenu?
    Try this:
    Qt Code:
    1. background-color: #ABABAB; /* sets background of the menu */
    2. border: 1px solid black;
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Stylesheet for ActionsContextMenu - how to?

    I don't see ActionsContextMenu being exposed for editing in Qt Designer. My guess is that your advise is applicable only if I can get ContextMenu from QWidget programmatically

    Looking through QWidget docs I can't find a way to retrieve this type of menu.
    Or - may be there is a way to get this menu for editing in Qt Designer?

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Stylesheet for ActionsContextMenu - how to?

    I meant,
    Call:
    Qt Code:
    1. qApp->setStyleSheet();
    To copy to clipboard, switch view to plain text mode 
    And pass the string in this, and check the results.

    Like this:
    Qt Code:
    1. QString ss("QMenu{background-color: #ABABAB;border: 1px solid black;}");
    2. qApp->setStyleSheet(ss);
    To copy to clipboard, switch view to plain text mode 

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

    QPlace (21st August 2009)

  6. #5
    Join Date
    Jul 2007
    Posts
    121
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Stylesheet for ActionsContextMenu - how to?

    Perfect. The only change I made is that I set setStyleSheet against control where I am setting the actionContextMenu. Setting it against application instance changes the main menu but not actionContextMenu in the control that I am interersted in.
    I suspect that it does not change in my case because I am setting custom stylesheet for the control _after_ application receives stylesheet change. I'll check it later.

    No. Changing stylesheet on QApp level does not change the stylesheet for the control's menu. Has to be done explicitly for the control.
    Thanks again!
    Last edited by QPlace; 21st August 2009 at 14:34.

  7. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Stylesheet for ActionsContextMenu - how to?

    Quote Originally Posted by QPlace View Post
    No. Changing stylesheet on QApp level does not change the stylesheet for the control's menu. Has to be done explicitly for the control.
    Then do it !

  8. The following user says thank you to yogeshgokul for this useful post:

    QPlace (21st August 2009)

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. stylesheet standard button names
    By h123 in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2009, 12:42
  3. stylesheet loading issue - thread
    By talk2amulya in forum Qt Programming
    Replies: 8
    Last Post: 26th February 2009, 12:53
  4. StyleSheet components using Qt designer
    By Kostanev in forum Qt Tools
    Replies: 1
    Last Post: 21st April 2008, 08:28
  5. Replies: 8
    Last Post: 17th March 2008, 14:04

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.