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. [SOLVED] help in getting focus to the dialog
QtWS25 Last Chance

[SOLVED] help in getting focus to the dialog

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 15.8k Views
  • 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #7

    i am looking for tab interaction. the tab key must work when the dialog displays. currently when the dialog displays over top of the mainwindow, the tab key works for the mainwindow, I am not sure about the signal and slots. it does not look like they could work but i could be wrong

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #8

      What are you wanting the tab key to do, exactly? Select the dialog? Or are you looking to be able to tab through the widgets on the main window, and then have the tab-action continue onto the dialog's widgets, too? Or something else?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #9

        when the dialog displays, there are widgets on the dialog that can be tabbed through but only those widgets on the dialog. The user would also have the option to click widgets on the mainwindow. this is why i have setmodal to false

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #10

          So to make sure I understand, you want to be able to interact with the mainwindow, but you want the dialog to always keep keyboard focus?

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #11

            yes. here is the code to the displaying of the dialog.

            dialog.h
            @#ifndef DIALOG_H
            #define DIALOG_H

            #include <QDialog>

            namespace Ui {
            class Dialog;
            }

            class Dialog : public QDialog
            {
            Q_OBJECT

            public:
            explicit Dialog(QWidget *parent = 0);
            ~Dialog();

            private:
            Ui::Dialog *ui;
            };

            #endif // DIALOG_H@

            mainwindow.h
            @#ifndef MAINWINDOW_H
            #define MAINWINDOW_H

            #include <QMainWindow>
            class Dialog;
            namespace Ui {
            class MainWindow;
            }

            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();

            private:
            Ui::MainWindow *ui;
            Dialog *tt;
            };

            #endif // MAINWINDOW_H@

            dialog.cpp
            @#include "dialog.h"
            #include "ui_dialog.h"

            Dialog::Dialog(QWidget *child) :
            QDialog(child),
            ui(new Ui::Dialog)
            {
            ui->setupUi(this);
            }

            Dialog::~Dialog()
            {
            delete ui;
            }@

            mainwindow.cpp
            @#include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "dialog.h"
            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            Dialog *tt = new Dialog(this);
            tt->show();
            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }@

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #12

              I'm not sure offhand (it's late here and I'm tired). You may be able to play with the "focusPolicy":http://doc.qt.nokia.com/latest/qwidget.html#focusPolicy-prop on your MainWindow (or it's components) and your Dialog. But that's just speculation. I'm not sure on what the details would be to implement such a thing.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kalster
                wrote on last edited by
                #13

                ok. i will read the focusPolicy. thank you for your help Mlong. goodnight.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #14

                  so if i click the pushbutton from the mainwindow, the dialog displays in focus but if i load the dialog when the mainwindow loads then the dialog does not have focus. is there a way to simulate a button being pressed? can i have some examples please?

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

                    You can't set the focus to the dialog in the constructor of the main window, as during this time, the main window has no focus.
                    The focus is set to the main window later on and after that time, you can move the focus, not before.

                    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
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #16

                      We have a similar setup in our application. We do it this way:

                      • in main method main() instantiate the MainWindow subclass
                      • call mainWindow->show()
                      • call mainWindow->slotShowDialog()
                      • call app.exec()

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        kalster
                        wrote on last edited by
                        #17

                        this topic is solved. I showed the mainwindow first and then the dialog right after it as in this code and it works great. i stumbled on this fix after i read Volker post.

                        comment the w.show(); in main.cpp and add this code to your mainwindow.cpp file
                        @this->show();
                        Dialog->show();@

                        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