tags:

views:

175

answers:

1

So far I've only had my main window pop up other windows that were QDialogs and I'm not getting it to work with a QWidget. The other window I want to display was designed with the Form Editor, then wrapped in a class called ResultViewer which extends QWidget (as opposed to QDialog). What I want is to have the ResultViewer show its ui in a seperate window. Now when I try to display it the ResultViewer ui just pops up in the main window on top of the mainwindow ui.

The code I'm using to display it is this (in my mainwindow.cpp file)

ResultViewer * rv = new ResultView(this);
rv->show();

The constructor for the ResultViewer looks like this

ResultViewer::ResultViewer(QWidget * parent) :
    QWidget(parent),
    ui(new Ui::ResultViewer)
{
    ui->setupUi(this);
}

I've looked through the QWidget documentation a bit but the only thing I can find that may be related is the QWidget::window() function, but the explanation isn't very clear, it just gives an example of changing the title of a window.

+3  A: 

If you just want to show second window in your application and have two top level widgets try to change:

ResultViewer * rv = new ResultView(this);
rv->show();

to

ResultViewer * rv = new ResultView();
rv->show();

Take a look on QWidget constructor documentation http://doc.trolltech.com/4.6/qwidget.html#QWidget to understand why it should be done in this way.

By the way QDialog is really good base class for additional windows in your application. I don't understand why you don't want to use it.

VestniK
Thanks VestniK, looking further into it I think I may actually switch to QDialog. Originally I didn't want to use it because they normally block the mainwindow while they're open but apparently that is easily changed.
Graphics Noob
Dialods can be modal and non modal. If you use QDialog::show() (actually this function inherited from QWidget) it's non modal (not blocking your main window) if you use QDialog::exec() your dialog is modal (blocks your main window).
VestniK