Results 1 to 12 of 12

Thread: Qt shortcut to hide QWidget

  1. #1
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt shortcut to hide QWidget

    Hi ,
    I am looking how I could use a QShortcut to make my main QWidget appear and disappear. I tried this but it only hide the widget I can't show() it again by the same shortcut:
    Qt Code:
    1. void ULmain::upShwHide()
    2. {
    3. if(m_visible)
    4. {
    5. //this->QWidget::hide();
    6. setVisible(true);
    7. m_visible = false;
    8. }
    9. else
    10. {
    11. //this->QWidget::show();
    12. setVisible(true);
    13. m_visible = true;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    I declared in my class constructor:
    Qt Code:
    1. QShortcut * shwHide = new QShortcut(QKeySequence("Ctrl+Space"), this);
    To copy to clipboard, switch view to plain text mode 
    and connect:
    Qt Code:
    1. QObject::connect(shwHide, SIGNAL(activated()), this, SLOT(upShwHide()));
    To copy to clipboard, switch view to plain text mode 

    I thought about a systemtray application but it doesn't seems to work.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qt shortcut to hide QWidget

    Quote Originally Posted by Nyx View Post
    Qt Code:
    1. ...
    2. setVisible(true);
    3. ...
    4. setVisible(true);
    5. ...
    To copy to clipboard, switch view to plain text mode 
    Something's wrong here ;-)

    Why not this?
    Qt Code:
    1. setVisible(!isVisible());
    To copy to clipboard, switch view to plain text mode 
    It makes the code a lot less complex and less error prone.

  3. #3
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    Thanks for your answer even with your code still doesn't work. The widget hide() but can't show().

  4. #4
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    However I tried both setVisible() method, hide() and show().

  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    my guess is : hiding your widget makes it loose keyboard focus, thus loosing shortcut sensitivity. I don't see any mean to show/hide your main widget using shortcut

  6. #6
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    I found an application (Launchy) wich uses Qt and this feature but I could't find the source code.

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qt shortcut to hide QWidget

    You can try and set a global shortcut.
    See the Qt extended library for a class that does this.
    http://www.qtcentre.org/threads/29969-LibQxt-0.6.0

  8. #8
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    I didn't found any class which does that in Qt extended library.
    What's a global shortcut?

  9. #9
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Qt shortcut to hide QWidget

    Quote Originally Posted by Nyx View Post
    I didn't found any class which does that in Qt extended library.
    What's a global shortcut?
    You must not have looked very hard.
    http://doc.libqxt.org/0.6.0/qxtglobalshortcut.html

  10. #10
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    Thanks. Do you know I could configure my .pro file?

  11. #11
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    The prog compile but still does not work. I'm under ubuntu 10.04.

  12. #12
    Join Date
    Jun 2010
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt shortcut to hide QWidget

    I tried with another shortcut (Ctrl+C) and it works!

Similar Threads

  1. setFocus after hide and show qwidget
    By alexandernst in forum Newbie
    Replies: 0
    Last Post: 14th April 2010, 17:25
  2. Can you hide the titlebar for a Qwidget in Windows?
    By sgmurphy19 in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2008, 21:28
  3. How to Disable or hide cursor from QWidget?
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th October 2007, 14:42
  4. Qt::WindowStaysOnTopHint vs. QWidget::hide()
    By gri in forum Qt Programming
    Replies: 1
    Last Post: 18th June 2007, 17:00
  5. shortcut with more than one key
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2007, 06:38

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.