Results 1 to 8 of 8

Thread: Disable popup menu

  1. #1
    Join Date
    Feb 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Disable popup menu

    Hi all,
    Can the popup menu be disabled in QMenu item using QT. Thats is, i have a menu named "File". But the sub menus like "Open, Close" etc not needed. I need to perform some operations on clicking "File" menu.
    Plz help.

  2. #2
    Join Date
    Mar 2009
    Posts
    25
    Thanked 2 Times in 2 Posts

    Default Re: Disable popup menu

    This is how you add a File menu,

    fileMenu = menuBar()->addMenu(tr("&File"));

    This is how you add a File action,

    menuBar()->addAction(fileAct);

    where fileAct is a normal action.


    However, this is strange behaviour.

    Either you only add actions to the menubar and no menu, or you use a toolbar instead.

  3. #3
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Disable popup menu

    I presume that Open and Close are menu items rather than submenus. When you added them to the QMenu, the return value was a QAction *. Call QAction::setEnabled(false) on those, to have them grayed out.

  4. #4
    Join Date
    Feb 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable popup menu

    Thnx for the replies.
    if SetEnabled() is used, the action is disabled. Then it is not possible to do any operations on clicking the QMenu. I need to do some operations on QMenu click. No need to show the action items.
    Plz suggest...

  5. #5
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable popup menu

    i m not sure about this, but what happens if u call setVisible(false) on you File menu..since its a QWidget, i believe it wont show..

  6. #6
    Join Date
    Feb 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable popup menu

    in this case, the Action will not be displayed. But cannot do any operation on clicking QMenu.
    I did a solution as: handled mousePressEvent/mouseReleaseEvent in a derived class of QMenu. Then i can perform the operation in menu click and no action needed here. But still i have a problem that the selection and focus is still in menu. So if i need to click another button i need to click it twice. I am not sure how to remove the selection and focus from menu.

  7. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable popup menu

    umm, how about setFocusPolicy(Qt::NoFocus)..but then it'll never have the focus..is that how you want it?

  8. #8
    Join Date
    Feb 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable popup menu

    i have found a solution:: send MouseButtonPress event in Release event.

    {
    QMouseEvent Event(QEvent::MouseButtonPress, pos(), Qt::LeftButton, 0, 0);
    QApplication::sendEvent(this, &Event);
    }
    Now it is working.......

Similar Threads

  1. Popup menu for a QGraphicsItem?
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2009, 21:27
  2. multi level menu popup
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2007, 08:06
  3. Replies: 4
    Last Post: 25th June 2007, 20:40
  4. ListView Dynamic Popup menu
    By raphaelf in forum Newbie
    Replies: 3
    Last Post: 14th October 2006, 19:26
  5. Replies: 6
    Last Post: 14th April 2006, 05:39

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.