Results 1 to 5 of 5

Thread: Caption in QMenu

  1. #1
    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 Caption in QMenu

    Hi,

    in Qt3's QPopupMenu one could insert a QLabel to get an Caption in a Menu. Qt4's QMenu is only providing a addAction(), which expects a QAction.
    Is there any possibility to get an Caption in QMenu?


    Thanks
    Lykurg

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Caption in QMenu

    Did you try the version of QMenu::addAction which takes a QString argument?

    And you can always use QMenu::setTitle() to make a menu with a title.

  3. #3
    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: Caption in QMenu

    Hi,
    Quote Originally Posted by wysota
    Did you try the version of QMenu::addAction which takes a QString argument?
    as result I get an QAction:
    Qt Code:
    1. myQMenu->addAction("some_text");
    2. // is the same as:
    3. QAction *act = new QAction(this);
    4. act->setText("some_text");
    5. myQMenu->addAction(act);
    To copy to clipboard, switch view to plain text mode 

    What I want is an "item", which is not clickable, checkable etc. and is not highlighted, when the cursor is above like the QActions. The "item" should be insert like an QAction, but behave like an QLabel. (It would be also nice when I could cusomize the frame...)

    Quote Originally Posted by wysota
    And you can always use QMenu::setTitle() to make a menu with a title.
    QMenu::setTitle() is only internal, right? The title isn't displayed in the GUI.

    Lykurg

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Caption in QMenu

    Quote Originally Posted by Lykurg
    What I want is an "item", which is not clickable, checkable etc. and is not highlighted, when the cursor is above like the QActions. The "item" should be insert like an QAction, but behave like an QLabel. (It would be also nice when I could cusomize the frame...)
    The only thing you could do is to disable the action.


    QMenu::setTitle() is only internal, right? The title isn't displayed in the GUI.
    It isn't marked as internal in the docs. I think it should behave exactly like the previous snippet.

  5. #5
    Join Date
    Mar 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Caption in QMenu

    This is an old thread, but I came across it while searching so I thought I would update it with a solution.

    You can use a QWidgetAction and then create a QLabel and set it with setDefaultWidget(). Then just add the QWidgetAction to the menu and you can style the QLabel freely.

Similar Threads

  1. QMenu popup: how close when clicked outside
    By powermax in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2009, 03:18
  2. QStyle : how to make the QMenu display in middle?
    By nish in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 27th November 2008, 10:39
  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 popup and close a QMenu
    By Placido Currò in forum Qt Programming
    Replies: 15
    Last Post: 14th May 2007, 16:41
  5. Qmenu Stable close on QTableWidget
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2006, 10: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.