![]() |
[PyQt] Can't neither setWindowFlags nor setFixedSize of a subwindow. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] Can't neither setWindowFlags nor setFixedSize of a subwindow. (/thread-34508.html) Pages:
1
2
|
Can't neither setWindowFlags nor setFixedSize of a subwindow. - JayCee - Aug-05-2021 I am trying to setWindowFlags (no maximize) and to make my subwindow NOT resizable, but setWindowFlags and setFixedSize are not doing it. No error messages. Everything else works. Here's a simplified version of my code. Thanks. Main window - main.py from PyQt5 import QtCore from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QMdiArea, QDesktopWidget, QMdiSubWindow import usuarios import sys class MainWin(QMainWindow): def __init__(self, parent=None): super(MainWin, self).__init__(parent) self.setupUI() self.setMinimumSize(1100, 600) area = self.frameGeometry() center = QDesktopWidget().availableGeometry().center() area.moveCenter(center) self.move(area.topLeft()) def setupUI(self): self.setGeometry(0, 0, 1050, 600) self.mdi = QMdiArea() self.toolBarItem = self.addToolBar("File") self.myAction = QAction("Usuários", triggered=self.showFormUsers) self.toolBarItem.addAction(self.myAction) self.setCentralWidget(self.mdi) def showFormUsers(self): self.subWindow = usuarios.formUsers() self.mdi.addSubWindow(self.subWindow) self.subWindow.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint) # No effect. The maximize button still appears. self.subWindow.setFixedSize(480, 300) # No effect. I can still resize the subwindow self.subWindow.show() if __name__ == '__main__': app = QApplication(sys.argv) win = MainWin() win.show() sys.exit(app.exec_())Subwindow - usuarios.py from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow class formUsers(QMainWindow): def __init__(self, parent=None): super(formUsers, self).__init__(parent) self.setWindowTitle("Usuários") # Input Fields ---------------------------------------------------------- > self.lineEdit_name = QtWidgets.QLineEdit(self, placeholderText="Name") self.lineEdit_name.setGeometry(QtCore.QRect(70, 80, 331, 20)) self.lineEdit_name.setObjectName("lineEdit_name") self.lineEdit_login = QtWidgets.QLineEdit(self, placeholderText="Login") self.lineEdit_login.setGeometry(QtCore.QRect(70, 110, 113, 20)) self.lineEdit_login.setObjectName("lineEdit_login") self.lineEdit_pwd = QtWidgets.QLineEdit(self, placeholderText="Password", echoMode=2) self.lineEdit_pwd.setGeometry(QtCore.QRect(70, 140, 113, 20)) self.lineEdit_pwd.setObjectName("lineEdit_pwd") # Push Buttons ---------------------------------------------------------- > self.pushButton_first = QtWidgets.QPushButton(self) self.pushButton_first.setGeometry(QtCore.QRect(50, 210, 75, 23)) self.pushButton_first.setObjectName("pushButton_first") self.pushButton_first.setText("<< First") self.pushButton_previous = QtWidgets.QPushButton(self) self.pushButton_previous.setGeometry(QtCore.QRect(140, 210, 75, 23)) self.pushButton_previous.setObjectName("pushButton_previous") self.pushButton_previous.setText("< Previous") self.pushButton_next = QtWidgets.QPushButton(self) self.pushButton_next.setGeometry(QtCore.QRect(230, 210, 75, 23)) self.pushButton_next.setObjectName("pushButton_next") self.pushButton_next.setText("Next >") self.pushButton_last = QtWidgets.QPushButton(self) self.pushButton_last.setGeometry(QtCore.QRect(330, 210, 75, 23)) self.pushButton_last.setObjectName("pushButton_last") self.pushButton_last.setText("Last >>") RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - Axel_Erfurt - Aug-05-2021 Is there a special reason to use pymysql? Python has sqlite3 and PyQt5 has QtSql. RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - JayCee - Aug-05-2021 I have a MySQL database on my local machine and I read I could use pymsql to connect to it. RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - Axel_Erfurt - Aug-05-2021 Often you don't need any extra modules at all. See here what python has to offer. https://docs.python.org/3/py-modindex.html RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - JayCee - Aug-05-2021 Thanks. RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - JokerSob - Aug-05-2021 (Aug-05-2021, 06:14 PM)JayCee Wrote: Hi, guys. My MDI application used to have all the code in one single file and everything worked, but now that I split the code I can't set the subwindow flags and its fixed size. No error messages. The subwindow opens just as if the code was no there. Everything else works exactly that way I want. The Mdi is in main.py and the subwindow in usuarios.py. Any ideas? Here's the code for both files. Thanks. line 3, in <module> import usuarios ModuleNotFoundError: No module named 'usuarios' RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - JayCee - Aug-05-2021 It's there. RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - Axel_Erfurt - Aug-05-2021 usuarios.py is in the first post RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - JayCee - Aug-06-2021 Still can't get rid of the maximize button and fix the subwindow size... I simplified the code so it's easier to understand: main.py from PyQt5 import QtCore from PyQt5.QtWidgets import QMainWindow, QApplication, QAction, QMdiArea, QDesktopWidget, QMdiSubWindow import usuarios import sys class MainWin(QMainWindow): def __init__(self, parent=None): super(MainWin, self).__init__(parent) self.setupUI() self.setMinimumSize(1100, 600) area = self.frameGeometry() center = QDesktopWidget().availableGeometry().center() area.moveCenter(center) self.move(area.topLeft()) def setupUI(self): self.setGeometry(0, 0, 1050, 600) self.mdi = QMdiArea() self.toolBarItem = self.addToolBar("File") self.myAction = QAction("Usuários", triggered=self.showFormUsers) self.toolBarItem.addAction(self.myAction) self.setCentralWidget(self.mdi) def showFormUsers(self): self.subWindow = usuarios.formUsers() self.mdi.addSubWindow(self.subWindow) self.subWindow.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint | QtCore.Qt.WindowCloseButtonHint) # No effect. The maximize button still appears. self.subWindow.setFixedSize(480, 300) # No effect. I can still resize the subwindow self.subWindow.show() if __name__ == '__main__': app = QApplication(sys.argv) win = MainWin() win.show() sys.exit(app.exec_())usuarios.py from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow class formUsers(QMainWindow): def __init__(self, parent=None): super(formUsers, self).__init__(parent) self.setWindowTitle("Usuários") # Input Fields ---------------------------------------------------------- > self.lineEdit_name = QtWidgets.QLineEdit(self, placeholderText="Name") self.lineEdit_name.setGeometry(QtCore.QRect(70, 80, 331, 20)) self.lineEdit_name.setObjectName("lineEdit_name") self.lineEdit_login = QtWidgets.QLineEdit(self, placeholderText="Login") self.lineEdit_login.setGeometry(QtCore.QRect(70, 110, 113, 20)) self.lineEdit_login.setObjectName("lineEdit_login") self.lineEdit_pwd = QtWidgets.QLineEdit(self, placeholderText="Password", echoMode=2) self.lineEdit_pwd.setGeometry(QtCore.QRect(70, 140, 113, 20)) self.lineEdit_pwd.setObjectName("lineEdit_pwd") # Push Buttons ---------------------------------------------------------- > self.pushButton_first = QtWidgets.QPushButton(self) self.pushButton_first.setGeometry(QtCore.QRect(50, 210, 75, 23)) self.pushButton_first.setObjectName("pushButton_first") self.pushButton_first.setText("<< First") self.pushButton_previous = QtWidgets.QPushButton(self) self.pushButton_previous.setGeometry(QtCore.QRect(140, 210, 75, 23)) self.pushButton_previous.setObjectName("pushButton_previous") self.pushButton_previous.setText("< Previous") self.pushButton_next = QtWidgets.QPushButton(self) self.pushButton_next.setGeometry(QtCore.QRect(230, 210, 75, 23)) self.pushButton_next.setObjectName("pushButton_next") self.pushButton_next.setText("Next >") self.pushButton_last = QtWidgets.QPushButton(self) self.pushButton_last.setGeometry(QtCore.QRect(330, 210, 75, 23)) self.pushButton_last.setObjectName("pushButton_last") self.pushButton_last.setText("Last >>") RE: Can't neither setWindowFlags nor setFixedSize of a subwindow. - Axel_Erfurt - Aug-06-2021 The problem is using QMainWindow as SubWindow, use QMdiSubWindow change the first lines in usuarios.py to from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMdiSubWindow class formUsers(QMdiSubWindow):and in main.py def showFormUsers(self): self.subWindow = usuarios.formUsers() self.subWindow.setFixedSize(480, 300) self.mdi.addSubWindow(self.subWindow) self.subWindow.show() |