PDA

View Full Version : new dialog hides behind... help me please



cooper
11th June 2009, 04:01
i open a dialog (dialog1) in main window, by using:

void MainWindow::on_action_View_triggered()
{
if (!dbdialog)
dbdialog = new dbDialog;
dbdialog->show();
dbdialog->raise();
dbdialog->activateWindow();
}

then, open another dialog (dialog2) by clicking a button in dialog1

void dbDialog::on_pushButton_search_clicked()
{
//dbdialog->isActiveWindow();
QTableView *tableView2;
tableView2 = new QTableView();
sqlModel2 = new QSqlQueryModel();
sqlModel2->clear();
tableView2->setModel(sqlModel2);
tableView2->show();
tableView2->raise();
tableView2->activateWindow();
}

my problem is that the dialog2 always hides behind dialog1, even if i click and drag dialog2.
i disabled dbdialog->raise(); dbdialog->activateWindow(); it still does the same thing.

is there any reason cause this happen?

thanks in advance.

nish
11th June 2009, 05:15
where is dialog2??

cooper
11th June 2009, 05:56
where is dialog2??

it is created by clicking a button in dialog1.

is that what you asking?
thanks

nish
11th June 2009, 07:14
where is the code in
void dbDialog::on_pushButton_search_clicked()
which calls dialog2?

cooper
11th June 2009, 22:36
where is the code in
void dbDialog::on_pushButton_search_clicked()
which calls dialog2?

hi Mrdeath, thanks for your reply. the dialog2 in my program is actually viewtable2. sorry about the confusing.
here is the code to open viewtable2 (i said "dialog2"):

void dbDialog::on_pushButton_search_clicked()
{
//dbdialog->isActiveWindow();
QTableView *tableView2;
tableView2 = new QTableView();
sqlModel2 = new QSqlQueryModel();
sqlModel2->clear();
tableView2->setModel(sqlModel2);
tableView2->show();
tableView2->raise();
tableView2->activateWindow();
}

i really appreciate your help.

nish
12th June 2009, 02:52
okay... this is the problem of parent and directly using tableview...

do it like this...


void dbDialog::on_pushButton_search_clicked()
{

//instead of creating this again n again.. make it member
QDialog* dlg=new QDialog(this);
QVBoxLayout* layout=new QVBoxLayout;
layout->setMargin(0);layout->setSpacing(0);

//instead of creating this again n again.. make it member
QTableView *tableView2;
tableView2 = new QTableView();
sqlModel2 = new QSqlQueryModel();
sqlModel2->clear();
tableView2->setModel(sqlModel2);

layout->addWidget(tableView2);

dlg->exec();

//dlg->show();
//dlg->raise();
//dlg->activateWindow();
}

you should create your own class inherited from QDialog.

cooper
12th June 2009, 05:48
thanks Mrdeath, it works

instead of just copy your code, would you like to give me a brief explanation of "it is a problem of parent and directly using tableview"?
i am a newbie in c++.

thanks for your time
you have a good weekend :)

nish
12th June 2009, 07:16
QDialog, and QMainWindow are generally the topLevel windows that should be used if u are using something independently.

because they provide several simplified top level window manager functions and return values.

secondly,,, every widget is shown in the geometry of its parent widget. since your tablewidget did not had any parent, it causes random behaviour and can be displayed anywhere... when i tried to display without parent it was showing at top left corner of the screen , and sometimes in middle

cooper
14th June 2009, 22:55
QDialog, and QMainWindow are generally the topLevel windows that should be used if u are using something independently.

...

anywhere... when i tried to display without parent it was showing at top left corner of the screen , and sometimes in middle

thanks Mrdeath, your explanation is quit helpful to me :)