Qt4: Placing QMainWindow instance inside other QWidget/QMainWindow

后端 未结 3 1851
感情败类
感情败类 2021-01-05 07:11

I\'d like to place QMainWindow instance inside another QWidget (for example centralWidget of another QMainWindow).

I\'m wondering why it doesn\'t work ? QMainWindow

相关标签:
3条回答
  • 2021-01-05 07:21
    centralwidget = new QMainWindow(this);
    centralwidget->setWindowFlags(Qt::Widget);
    setCentralWidget(centralwidget);
    

    This should help.

    0 讨论(0)
  • 2021-01-05 07:34

    Having the same problem, I found the solution here.

    QMainWindow sets its window type to Qt::Window so that it will be in an independent window even if it has a parent (you can confirm this by calling show() on your QMainWindow, and you will see it in its own window). Try adding the line

    window->setWindowFlags(Qt::Widget);
    

    after you construct the QMainWindow.

    0 讨论(0)
  • 2021-01-05 07:40

    QMainWindow provides predefined stuff like toolbars and status bars and menu bars in a platform agnostic way (it "does the right thing", without manual intervention). If all you need is a bunch of buttons in a layout, use QWidget.

    You need to make sure each QMainWindow has centralQWidget`, other than that, you should be fine.

    0 讨论(0)
提交回复
热议问题