September 14, 2011

Anna Anna
Lab Rat
21 posts

Extra window or ui in existing gui

Page  
1

Hello to all,

I would like to know how I can embed an extra window or another ui in my mainclass gui.

I have a gui that I created with the help of the designer as main class with several elements like buttons. In this gui I need to have a frame / window / ui that can expand to fullscreen size, wenn I push a button in the outer gui. The frame / window / ui that’s supposed to be shown fullscreen should contain elements a pixmap, labels and lcdnumbers.

My approach was:

  • define a member widget in the main class
  • creating an instance widget in the constructor with a rectangle geometry, showing it

How can I embed this window in my ui? or is something else than a window widget more useful?

16 replies

September 14, 2011

p-himik p-himik
Lab Rat
263 posts

You can create new Qt Designer Form Class and promote widgets from main ui to it.

September 14, 2011

Anna Anna
Lab Rat
21 posts

p-himik, I’ll try and create that class.

once created, how can I embed it in my main ui? with a certain position etc.

and can I let it show then with .showfullscreen() ? (only the second ui)

September 14, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

Hi Anna,

one question:

do you want to achieve something like in typical editors: Floating child windows that can be maximized insid ethe main window? if yes, have a look at QMdiArea [doc.qt.nokia.com]

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

Anna Anna
Lab Rat
21 posts

that is not exactly what I have in mind…

the second ui shoud be able to be maximized to fullscreen size. no matter what resolution the sreen has.
so the ui would be the only thing to be seen.

is that possible?

September 14, 2011

p-himik p-himik
Lab Rat
263 posts

1) Put simple QWidget on your main ui
2) Promote it to your second ui’s class (right button on the simple QWidget -> Promote to…)
3) In the slot connected to the “Go fullscreen” button place following code (replace secondUiWidget with your’s widget’s object name):

  1. setWindowFlags( Qt::Window );
  2. showFullScreen();

4) 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.

September 14, 2011

Anna Anna
Lab Rat
21 posts

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?

September 14, 2011

sierdzio sierdzio
Area 51 Engineer
4965 posts

you probably want to look at QKeyEvent [developer.qt.nokia.com] doc.
Since this is UI, you can also take a look at QWidget::keyPressedEvent [developer.qt.nokia.com] virtual slot

 Signature 

(Z(:^

September 14, 2011

p-himik p-himik
Lab Rat
263 posts

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.

September 14, 2011

Anna Anna
Lab Rat
21 posts

p-himik,
like this?

  1. QAction* escape = new QAction(this);
  2.     escape->shortcut(Qt::Key_Escape);
  3.    
  4.     ui->widget->addAction(escape);
  5.            

how can a function / slot be triggered by this key now?

September 14, 2011

Anna Anna
Lab Rat
21 posts

this code isn’t right… “ no matching function for call to ‘QAction::shortcut(Qt::Key)’ “

September 14, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

Hi Anna,

have a look at the docs of QAction: [doc.qt.nokia.com]

change shortcut(xxx) to setShortcut(xxx) and it should work.

Additionally, have a look at the shortcutContext property [doc.qt.nokia.com]

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

Anna Anna
Lab Rat
21 posts

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:

  1. Andon::Andon(QWidget *parent) :
  2.     QWidget(parent),
  3.     ui(new Ui::Andon)
  4. {
  5.     ui->setupUi(this);
  6.    
  7.     timer = new QTimer(this);
  8.  
  9.     connect(timer, SIGNAL(timeout()), ui->widget, SLOT(showTime()));
  10.  
  11.     QAction* escape = new QAction(this);
  12.     escape->setShortcut(Qt::Key_Escape);
  13.     escape->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  14.     ui->widget->addAction(escape);
  15.     connect(escape, SIGNAL(changed()), this, SLOT(exit()));
  16. }

and this is the exit slot:

  1. void Andon::exit()
  2. {
  3.     timer->stop();
  4.     ui->widget->showNormal();
  5. }

what could be wrong?

September 14, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

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.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

September 14, 2011

Anna Anna
Lab Rat
21 posts

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

September 14, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

ups, I meant triggered() :-)

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

Page  
1

  ‹‹ QUrl and special characters(#)      [ SOLVED ]Problem in getting mouseEvent on QTableWidget ››

You must log in to post a reply. Not a member yet? Register here!