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
3: import sys
5: def setToolbar(type):
6: layout = QtGui.QVBoxLayout(type)
8: tool = QtGui.QToolBar("MyTools", type)
9: a = tool.addAction(QtGui.QAction("Foo", type))
13: if __name__=='__main__':
14: app = QtGui.QApplication(sys.argv)
18: dialogWin.setWindowTitle("QDialog Window")
24: widgetWin.setWindowTitle("QWidget Window")
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.
Blog, Website Content, VFX Showreel work & Tools & Scripts by Sanjeev Kumar is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.