Reputation: 836
PyQt is not showing Button if i set window to showMaximize()
If i set a self.setGeometry(50, 50, 500, 300) then the Button is showing perfectly Facing issue at showMaximized()
import sys
from PyQt4 import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.showMaximized()
self.setWindowTitle("PyQT tuts!")
self.setWindowIcon(QtGui.QIcon('pythonlogo.png'))
self.home()
def home(self):
btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
btn.resize(100, 100)
btn.move(100, 100)
self.show()
def run():
app = QtGui.QApplication(sys.argv)
GUI = Window()
sys.exit(app.exec_())
run()
Any Help Would be appreciated ,
I need to place the Button at center of my Window .
Upvotes: 0
Views: 306
Reputation: 243897
The problem is that the children are shown by the parents, in your case when the parent is shown the button is not yet a child so it will not be shown, so there are 2 possible solutions:
Set as a child before showMaximized()
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.home()
self.showMaximized()
self.setWindowTitle("PyQT tuts!")
self.setWindowIcon(QtGui.QIcon('pythonlogo.png'))
call the show method of the button.
def home(self):
btn = QtGui.QPushButton("Quit", self)
btn.clicked.connect(QtCore.QCoreApplication.instance().quit)
btn.resize(100, 100)
btn.move(100, 100)
btn.show()
Upvotes: 1