Reputation: 1
i am learning PyQt and tried to put a QDialog inside a QMainWindow (to mix layouts). I just don't get why i have 2 separated windows instead of my Dialog inside the MainWindow.
Tks in advance.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Btns(QtGui.QDialog):
def __init__(self, parent=None):
super(Btns, self).__init__(parent)
grid = QtGui.QGridLayout(self)
self.setLayout(grid)
btnv=QtGui.QPushButton("valider")
grid.addWidget(btnv, 0,0)
btna=QtGui.QPushButton("annuler")
grid.addWidget(btna,0,1)
btns=QtGui.QPushButton("sortir")
grid.addWidget(btns, 1,1)
btnr=QtGui.QPushButton("retour")
grid.addWidget(btnr, 1,0)
self.show()
class MaFenetre(QtGui.QMainWindow):
def __init__(self):
super(MaFenetre, self).__init__()
self.initMb()
self.initBtns()
def initMb(self):
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu('&Fichier')
def initBtns(self):
btns = Btns(self)
def main():
app = QtGui.QApplication(sys.argv)
mf = MaFenetre()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Upvotes: 0
Views: 1402
Reputation: 11849
The QDialog class is the base class of dialog windows. A dialog window is a top-level window mostly used for short-term tasks and brief communications with the user.
[Source: Qt Documentation on QDialog]
QDialog is supposed to make a new window! If you don't want a new window, don't use a QDialog
. Consider using QWidget
instead.
Upvotes: 1