How to make another window pop up that extends QWidget as opposed to QDialog?
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 to开发者_StackOverflow社区p 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.
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.
精彩评论