Simple way to embed a QDialog into a QWidget

2019-05-17 19:53发布

I have been searching for a simple way to embed QDialog instances in a QWidget, but all I found used OpenGL or some rather complex stuff to achieve that. Actually, all the examples I found tried to achieve many more things than simply embed the QDialog. So, I am wondering: is there a simple and clean way to embed a QDialog in a QWidget?

P.S.: I tagged since it's what I'm using, but I will of course accept c++ answers :)

Here is a screen capture of the piece of software I have to port and for which I kind of need such a feature.

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-17 20:27
myDialog->setWindowFlags(Qt::Widget); // to embed dialog as a simple widget
查看更多
贪生不怕死
3楼-- · 2019-05-17 20:36

You should use QMdiArea.

widget = QWidget()
mdiarea = QMdiArea() 
layout = QVBoxLayout(widget)
layout.addWidget(mdiarea)
d = QInputDialog()
d.setLabelText("test2")
d.setInputMode(QInputDialog.TextInput)
w = mdiarea.addSubWindow(d)
w.show()
widget.show()
查看更多
登录 后发表回答