Extra window or ui in existing gui
-
- Put simple QWidget on your main ui
- Promote it to your second ui's class (right button on the simple QWidget -> Promote to...)
- In the slot connected to the "Go fullscreen" button place following code (replace secondUiWidget with your's widget's object name):
@setWindowFlags( Qt::Window );
showFullScreen();@ - In the slot connected to button returning second ui to it's normal state you have to do the opposite (i'm not sure but i think that you'll need to restore widget's geometry too).
I didn't test it, but i will if it won't do the job.
-
thank you, p-himik!
creating the window and maximzing it worked perfectly :-)
but I figured that I need to connect the function to go back to normal size to the signal from the esc-key.
can somebody tell me how to implement that? do I have to create an event?
-
you probably want to look at "QKeyEvent":http://developer.qt.nokia.com/doc/qt-4.7/qkeyevent.html doc.
Since this is UI, you can also take a look at "QWidget::keyPressedEvent":http://developer.qt.nokia.com/doc/qt-4.7/qwidget.html#id-e6f38482-7464-4202-b7a9-fcc07427fd75 virtual slot -
Also if for some reason you don't want to reimplement QWidget::keyPressedEvent (which is, by the way, not a slot) you can create new QAction, assign a shortcut to it and invoke QWidget::addAction() for your second ui's widet.
-
p-himik,
like this?
@QAction* escape = new QAction(this);
escape->shortcut(Qt::Key_Escape);ui->widget->addAction(escape); @
how can a function / slot be triggered by this key now?
-
this code isn't right... " no matching function for call to 'QAction::shortcut(Qt::Key)' "
-
Hi Anna,
have a look at the "docs of QAction:":http://doc.qt.nokia.com/latest/qaction.html#shortcut-prop
change shortcut(xxx) to setShortcut(xxx) and it should work.
Additionally, have a look at the "shortcutContext property":http://doc.qt.nokia.com/latest/qaction.html#shortcutContext-prop
-
thank you, Gerolf!
I still can't get it to work.
that's what I 've implemented in the constructor of the main widget class:
@Andon::Andon(QWidget *parent) :
QWidget(parent),
ui(new Ui::Andon)
{
ui->setupUi(this);timer = new QTimer(this); connect(timer, SIGNAL(timeout()), ui->widget, SLOT(showTime())); QAction* escape = new QAction(this); escape->setShortcut(Qt::Key_Escape); escape->setShortcutContext(Qt::WidgetWithChildrenShortcut); ui->widget->addAction(escape); connect(escape, SIGNAL(changed()), this, SLOT(exit()));
}@
and this is the exit slot:
@void Andon::exit()
{
timer->stop();
ui->widget->showNormal();
}@what could be wrong?
-
Are you sure the input focus is on a child of the widget?
why do you connect the c hanged signal? I typically use triggered(bool) and connect it to a slot like yours.
-
the input focus is the widget itself, I guess. (ui->widget)
as described earlier, I show the widget fullscreen and I would like to show it normally with the held of the ecs key.
which signal should I take: triggered() or toggled(bool)? (there is no triggered(bool))
but so far, it doesn't work with neither of them -
ups, I meant triggered() :-)
-
works now! thank you :)