Results 1 to 6 of 6

Thread: QMenu popup: how close when clicked outside

  1. #1
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMenu popup: how close when clicked outside

    Hi,

    I have 2 QMenus (trayIconMenu1 and trayIconMenu2).

    Qt Code:
    1. QMenu *trayIconMenu1 = new QMenu(this);
    2. QMenu *trayIconMenu2 = new QMenu(this);
    To copy to clipboard, switch view to plain text mode 

    The first QMenu popups itself when i right click the icon in the system tray. I popup the second one when i left click the icon in the system tray.

    Qt Code:
    1. trayIconMenu2->popup(QCursor::pos());
    To copy to clipboard, switch view to plain text mode 

    The problem is that the second one does not automatically close whenever i click outside the menu. The first one does close automatically.

    I tried to inherit QMenu and overwrite mousePressEvent, changeEvent, focusOutEvent, event. I also tried these functions in the parent widget, which is a QDialog. None of these functions are called when I click outside the popup.

    What event should I use so that the second QMenu automatically closes? Or is there something else I need to do?

    Thx

  2. #2
    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: QMenu popup: how close when clicked outside

    why dont u close your first menu when u pop-up your second menu?

  3. #3
    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: QMenu popup: how close when clicked outside

    Or perhaps you could dynamically populate the menu with help of QMenu::aboutToShow().
    J-P Nurmi

  4. #4
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu popup: how close when clicked outside

    Thx for the replies.

    @talk2amulya
    The second menu and the first menu are independent of each other. When I left click the system tray icon only the second menu should popup. (The first menu only shows when I right click the system tray icon.) So the second menu should close in every case I press the mouse (left, right or middle click) somewhere outside the menu. The first menu is never invoked.

    @jpn
    I also thought of this to use it somewhere in the proces, but I dont see how I can use this function to close the second menu.

    I would expect an event when I click outside the menu, but I cant find it.
    So I don't understand what exactly happens when the user right clicks the menu followed by a click outside the menu. It seems like qt does some extra things in that case and not when the user does the same with a left click.

  5. #5
    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: QMenu popup: how close when clicked outside

    Quote Originally Posted by powermax View Post
    @jpn
    I also thought of this to use it somewhere in the proces, but I dont see how I can use this function to close the second menu.
    Actually my idea was to use a single menu instead of two menus. For example you could try to use QSystemTrayIcon::Trigger vs. QSystemTrayIcon::Context to determine how to re-populate the menu on the fly.
    J-P Nurmi

  6. #6
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu popup: how close when clicked outside

    It works now. I need to use the following code:
    Qt Code:
    1. trayIconMenu2->activateWindow();
    2. trayIconMenu2->popup(QCursor::pos());
    To copy to clipboard, switch view to plain text mode 
    Now I will dynamically populate my menu .
    Thx for the hints.
    Last edited by powermax; 4th March 2009 at 04:24.

Similar Threads

  1. how to popup and close a QMenu
    By Placido Currò in forum Qt Programming
    Replies: 15
    Last Post: 14th May 2007, 17:41
  2. Qmenu Stable close on QTableWidget
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 17th July 2006, 11:03
  3. Can't close my popup
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2006, 10:10
  4. Replies: 6
    Last Post: 14th April 2006, 06: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.