[SOLVED] help in getting focus to the dialog
-
as soon as my program loads, i have a dialog displayed over top of the mainwindow. The dialog is not focused but the mainwindow is. the tab key works for the mainwindow but instead i would like it to work with the dialog. how to set focus to the dialog so that it acts at if i clicked on the title of the dialog.
I have tried all of the following without any luck in getting focus to the dialog.
@ this->clearFocus();
this->setFocus();
this->raise();
this->activateWindow();@EDIT: this topic is solved. go to page 2 to find out how to set focus to the dialog when setModal is false.
-
[quote author="kalster" date="1312954398"]yes setModal to true works but i need to interact with the mainwindow when the dialog is displayed. therefore, i have setModal to false. [/quote]
What kind of interaction do you want? Anything signals and slots could help with?
-
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
-
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_OBJECTpublic:
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_OBJECTpublic:
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;
}@ -
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.
-
-
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();@