How to make QWidget appear in a separate window?

I have

class MyWidget : public QWidget
{
    Q_OBJECT
public:
    explicit MyWidget (QWidget *parent);
    // ...
};

// here is ALL the code in MyWidget constructor
MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    glWidget = new GLWidget(this, cluster);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(glWidget);
    setLayout(mainLayout);

    setWindowTitle("Visualization");
}

and the main window MainWindow w;.

I want to

  • to create new instances of MyWidget from w;
  • so that instances are destroyed after QCloseEventor w(now they are destroyed only after QCloseEvent);
  • so that instances appear in new windows.

I create a new instance MyWidgetas follows:

void MainWindow::visualize()
{
    MyWidget *widg = new MyWidget(this); // or widg = new MyWidget(0)
    widg->show();
    widg->raise();
    widg->activateWindow();
}

When I try to create widgwith whow parent, it widgappears inside w(in the upper left corner).

What is the easiest and most understandable way to fix this?

Thank!

+5
source share
2 answers
MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent, Qt::Window)
{
    glWidget = new GLWidget(this, cluster);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(glWidget);
    setLayout(mainLayout);

    setWindowTitle("Visualization");
}

Qt::Window QWidget , .

+10

QWidget , , 0. 0, mens "YOU":) - - - , ( , ).

+2

All Articles