Simple way to embed a QDialog into a QWidget

﹥>﹥吖頭↗ 提交于 2019-12-22 09:34:40

问题


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 pyqt 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.


回答1:


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()



回答2:


myDialog->setWindowFlags(Qt::Widget); // to embed dialog as a simple widget


来源:https://stackoverflow.com/questions/17163585/simple-way-to-embed-a-qdialog-into-a-qwidget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!