PDA

View Full Version : Qt shortcut to hide QWidget



Nyx
18th June 2010, 17:34
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:

void ULmain::upShwHide()
{
if(m_visible)
{
//this->QWidget::hide();
setVisible(true);
m_visible = false;
}
else
{
//this->QWidget::show();
setVisible(true);
m_visible = true;
}
}

I declared in my class constructor:

QShortcut * shwHide = new QShortcut(QKeySequence("Ctrl+Space"), this);
and connect:

QObject::connect(shwHide, SIGNAL(activated()), this, SLOT(upShwHide()));

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

tbscope
18th June 2010, 17:57
...
setVisible(true);
...
setVisible(true);
...


Something's wrong here ;-)

Why not this?

setVisible(!isVisible());
It makes the code a lot less complex and less error prone.

Nyx
19th June 2010, 10:47
Thanks for your answer even with your code still doesn't work. The widget hide() but can't show().

Nyx
19th June 2010, 10:51
However I tried both setVisible() method, hide() and show().

totem
19th June 2010, 12:42
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

Nyx
19th June 2010, 12:52
I found an application (Launchy) wich uses Qt and this feature but I could't find the source code.

tbscope
19th June 2010, 17:04
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

Nyx
19th June 2010, 19:18
I didn't found any class which does that in Qt extended library.
What's a global shortcut?

tbscope
19th June 2010, 21:14
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

Nyx
20th June 2010, 12:02
Thanks. Do you know I could configure my .pro file?

Nyx
20th June 2010, 12:29
The prog compile but still does not work. I'm under ubuntu 10.04.

Nyx
24th June 2010, 19:12
I tried with another shortcut (Ctrl+C) and it works!