Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Implementing MenuBar AutoHide function

  1. #1
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question Implementing MenuBar AutoHide function

    Expert advise needed!

    Does QT4 provide any such feature? Or must one detect mouse positions and manually calculate if the menubar should be hidden (read: empty all items from menubar)?

    Cheers,
    Viking.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing MenuBar AutoHide function

    U can use QWidget::hide () to hide the menubar... as menu bar is derived from QWidget

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Implementing MenuBar AutoHide function

    Quote Originally Posted by viking View Post
    (read: empty all items from menubar)?
    What sense would it make to remove all items from the menu bar? It wouldn't hide the menu itself, would it? And if you hide the menu bar... how do you want to bring it back (I don't say it's not possible)?

  4. #4
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Implementing MenuBar AutoHide function

    10q aamer4yu,

    That indeed is a better idea. Dint strike me.
    But anyway, the mouse position will have to be manually monitored.

    -vkng

  5. #5
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by wysota View Post
    What sense would it make to remove all items from the menu bar? It wouldn't hide the menu itself, would it? And if you hide the menu bar... how do you want to bring it back (I don't say it's not possible)?
    An empty menu bar is not displayed. Well, that was my thinking.
    But aamer4yu has suggested a better solution.

    Bringing the menubar back should be easy. Just repopulate the menubar with the previously saved menu items.

    -vkng

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing MenuBar AutoHide function

    What wysota meant was removing items wont hide the menu bar..... dont question his knowledge about Qt.... I dont stand anywhere near him....

    also to hide/ show the menu bar u can use some keyboard shortcuts, or provide the same from toolbar...
    and if u want that some actions in the menu shouldnt work, just disable the actions....

  7. #7
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by aamer4yu View Post
    What wysota meant was removing items wont hide the menu bar..... dont question his knowledge about Qt.... I dont stand anywhere near him....

    also to hide/ show the menu bar u can use some keyboard shortcuts, or provide the same from toolbar...
    and if u want that some actions in the menu shouldnt work, just disable the actions....
    No pun intended guys

    about the actions, actually i indeed need an autohide menubar. so i guess i'll just have to track the mouse movements...

  8. #8
    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: Implementing MenuBar AutoHide function

    By the way, just as a side note, possible shortcuts assigned to menu actions won't trigger while the menu bar is hidden.
    J-P Nurmi

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Implementing MenuBar AutoHide function

    An empty menu bar is not displayed if you don't populate it, because it's not created. When you do created, things change. Anyway, if you hide the menu bar, how will you know when you want to get it back?

  10. #10
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by wysota View Post
    An empty menu bar is not displayed if you don't populate it, because it's not created. When you do created, things change. Anyway, if you hide the menu bar, how will you know when you want to get it back?
    1. I see. Well, that rules out my idea. I will have to hide it.
    2. If I hide the menubar, I will have to calculate the coords in the mouseMove Event and if they are near the menubar location on the mainwindow, i show the menubar. would it work?

    -vk

  11. #11
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by jpn View Post
    By the way, just as a side note, possible shortcuts assigned to menu actions won't trigger while the menu bar is hidden.
    thanks jpn. i shall keep that in mind. however, my primary focus is to implement an autohide menubar. but your suggestion is good.

    vk

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: Implementing MenuBar AutoHide function

    Quote Originally Posted by viking View Post
    2. If I hide the menubar, I will have to calculate the coords in the mouseMove Event and if they are near the menubar location on the mainwindow, i show the menubar. would it work?
    If you enable mouse tracking then yes. But you'll have to do it in an event filter which you have to apply on your central widget and any of its subwidgets, because if a subwidget handles a mouse move event itself, it won't propagate it to the parent. Of course you'll have to calculate the coordinates in the main window coordinate system. Lots of work

  13. #13
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing MenuBar AutoHide function

    See the attachment...
    hope this helps
    Attached Files Attached Files

  14. The following user says thank you to aamer4yu for this useful post:

    viking (29th March 2007)

  15. #14
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by wysota View Post
    If you enable mouse tracking then yes. But you'll have to do it in an event filter which you have to apply on your central widget and any of its subwidgets, because if a subwidget handles a mouse move event itself, it won't propagate it to the parent. Of course you'll have to calculate the coordinates in the main window coordinate system. Lots of work
    Yes! Thanks for your inputs. btw, what component could replace the trapezoidal menubar that appears on the top when you connect to Remote Desktop in Windows. Basically that is what I am trying to achieve. Limitation of a menu bar is that it must only be applied to a gui component that is of type QMainWindow. But what if I wanted to add an Autohide Bar on the top of the screen like the one we see when connecting to a remote computer using mstsc in Windows?

  16. #15
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by aamer4yu View Post
    See the attachment...
    hope this helps
    Quote Originally Posted by aamer4yu View Post
    See the attachment...
    hope this helps
    Thanks a ton aamer4yu for this. I really appreciate it! I tried out the app. I feel it needs some debuggings coz in the function

    Qt Code:
    1. void CMainWindow::initial()
    2. {
    3. menuBarRect = menuBar()->geometry();
    4. menuBar()->hide();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    the moment the menubar hides, the Y2 in the geometry becomes -1. hence, goin forward,
    Qt Code:
    1. if(menuBarRect.contains(mousePos) )
    2. {
    3. menuBar()->show();
    4. isMenuOn = true;
    5. }
    6. else
    7. {
    8. menuBar()->hide();
    9. isMenuOn = false;
    10. }
    To copy to clipboard, switch view to plain text mode 
    control never enters the if part, it always goes into the else. i'll look into it. of course your inputs would be valuable.

    as i replied to wysota, i actually want to implement the trapezoidal menubar that appears on the top when you connect to Remote Desktop in Windows. the one with a fancy PIN button that toggles autohide... still searching for a way to do that... any help wud be appreciated!

  17. #16
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Arrow Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by aamer4yu View Post
    See the attachment...
    hope this helps
    I changed the function, not in the best possible way, but its working now...

    Qt Code:
    1. void CMainWindow::mouseMoveEvent ( QMouseEvent * event )
    2. {
    3. QPoint mousePos;
    4. mousePos = event->pos();
    5.  
    6. if( (menuBarRect.bottom() + 20) > mousePos.y() )
    7. {
    8. menuBar()->show();
    9. isMenuOn = true;
    10. }
    11. else
    12. {
    13. menuBar()->hide();
    14. isMenuOn = false;
    15. }
    16.  
    17. QMainWindow::mouseMoveEvent(event);
    18. }
    To copy to clipboard, switch view to plain text mode 

  18. #17
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing MenuBar AutoHide function

    Seems u havent understood my program or I have understood what u wanted.
    I implemented auto hide like in taskbar in windows.

    What I do is, initially using the single shot timer I capture the geometry of the menubar. This is a private member, so its value is retained. As soon as I set the geometry cordinated in menuBarRect, I hide the menubar. So u wont see a menubar initially.
    When u move the mouse in the upper part of the window, where the menu is supposed to appear, I capture it, and show the menubar.

    Did u try running the code ?? or u just walked thru manually ?? also isMenuOn variable is not needed. I was just trying with that variable, and forgot to delete it.

    Also I havent seen your "trapezoidal menubar that appears on the top when you connect to Remote Desktop in Windows." so cant help u on that right now...

    if u have problem in running my code, ask me....

  19. #18
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Implementing MenuBar AutoHide function

    what error were u getting before editing the code ??
    it was working fine for me...

  20. #19
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by aamer4yu View Post
    Seems u havent understood my program or I have understood what u wanted.
    I implemented auto hide like in taskbar in windows.

    What I do is, initially using the single shot timer I capture the geometry of the menubar. This is a private member, so its value is retained. As soon as I set the geometry cordinated in menuBarRect, I hide the menubar. So u wont see a menubar initially.
    When u move the mouse in the upper part of the window, where the menu is supposed to appear, I capture it, and show the menubar.

    Did u try running the code ?? or u just walked thru manually ?? also isMenuOn variable is not needed. I was just trying with that variable, and forgot to delete it.

    Also I havent seen your "trapezoidal menubar that appears on the top when you connect to Remote Desktop in Windows." so cant help u on that right now...

    if u have problem in running my code, ask me....
    @ I did! And I ran it in debug mode as well. Thats when i found out that the control never enters to the part where it is supposed to show the menubar.

    @ I'll try to send you a screenshot of that "trapezoidal menubar that appears on the top when you connect to Remote Desktop in Windows." But hey, thanks for all the time man! Appreciate it a lot !!!

  21. #20
    Join Date
    Mar 2007
    Location
    India
    Posts
    27
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Implementing MenuBar AutoHide function

    Quote Originally Posted by aamer4yu View Post
    what error were u getting before editing the code ??
    it was working fine for me...
    It was? Thats strange. It did not work for me. I'll try again with your code. And try to find out.

Similar Threads

  1. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  3. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  4. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

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.