Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Extra window or ui in existing gui
Forum Updated to NodeBB v4.3 + New Features

Extra window or ui in existing gui

Scheduled Pinned Locked Moved General and Desktop
17 Posts 4 Posters 6.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anna
    wrote on last edited by
    #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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anna
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          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":http://doc.qt.nokia.com/latest/qmdiarea.html

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anna
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              p-himik
              wrote on last edited by
              #6
              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):
                @setWindowFlags( Qt::Window );
                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.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anna
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  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

                  (Z(:^

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    p-himik
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Anna
                      wrote on last edited by
                      #10

                      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?

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Anna
                        wrote on last edited by
                        #11

                        this code isn't right... " no matching function for call to 'QAction::shortcut(Qt::Key)' "

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on last edited by
                          #12

                          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

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

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            Anna
                            wrote on last edited by
                            #13

                            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?

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #14

                              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.

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

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                Anna
                                wrote on last edited by
                                #15

                                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

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  giesbert
                                  wrote on last edited by
                                  #16

                                  ups, I meant triggered() :-)

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

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    Anna
                                    wrote on last edited by
                                    #17

                                    works now! thank you :)

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved