Demonstrating the difference & similarity between QDialog, QWidget and QMainWindow
Run this code and the difference will be clear and you will be ready to go what to choose out of QDialog, QWidget or QMainWindow, QMainWindow is at the topmost level.
1: from PyQt4 import QtCore,QtGui
2:
3: import sys
4:
5: def setToolbar(type):
6: layout = QtGui.QVBoxLayout(type)
7: layout.setMargin(0)
8: tool = QtGui.QToolBar("MyTools", type)
9: a = tool.addAction(QtGui.QAction("Foo", type))
10: layout.addWidget(tool)
11: layout.addStretch()
12:
13: if __name__=='__main__':
14: app = QtGui.QApplication(sys.argv)
15: app.setStyle("CleanLooks")
16:
17: dialogWin=QtGui.QDialog()
18: dialogWin.setWindowTitle("QDialog Window")
19: dialogWin.setGeometry(100,230,270,210)
20: setToolbar(dialogWin)
21: dialogWin.show()
22:
23: widgetWin=QtGui.QWidget()
24: widgetWin.setWindowTitle("QWidget Window")
25: widgetWin.setGeometry(400,230,270,210)
26: setToolbar(widgetWin)
27: widgetWin.show()
28:
29: mainWindow=QtGui.QMainWindow()
30: mainWindow.setWindowTitle("QMainWindow")
31: mainWindow.setGeometry(700,230,270,210)
32: setToolbar(mainWindow)
33: mainWindow.show()
34:
35:
36: sys.exit(app.exec_())
I have made a function to set the toolbar for every type of window. After you run the code you will notice you can do most of the work with each type if window except you cannot minimize or maximize the QDialog window, and QMainWindow has advantage of giving floating toolbar by default.
Note: you are not suppose to run this code from Maya, because maya window itself is running the main thread.