Mar-20-2020, 11:51 PM
(This post was last modified: Mar-20-2020, 11:51 PM by deanhystad.)
mnash you are doing way too much typing. I usually let the Qt pick my fonts. But if I really wanted a particular font I would use a style sheet file that I would load into the application instead of hard coding a font. If you really want to hard code fonts at least use a convenient constructor:
MainWindow.setFont(QFont("Times", 10, QFont.Bold))And what's with the odd class methods? If you are writing window classes by hand, all the examples are written the same way. You define a class for each window. You make all the widgets inside the __init___ method. The script calls QApplicaiton, creates instances of the window classes, draws a window (or more) and calls app.exec_.
import stuff class MyCustomWindow(QtWidgets.QMainWindow): # <- A custom QMainWindow def __init__(self): # <- Called when instances is created super().__init__() # <- Do __init__ for QMainWindow self.setWindowTitle('Window Title') self.menubar = QtWidgets.QMenuBar(MainWindow) # Do not set the geometry. Let the window take care of this auromatically # self.menubar.setGeometry(QtCore.QRect(0, 0, 1920, 18)) self.menubar.setObjectName("menubar") self.setMenuBar(self.menubar) self.layout = QVBoxLayout(self) # <- Use a layout manager self.button = QPushButton() # <-Use default font self.set_button_style('SCAN', 'rgb(0, 250, 0)') self.button.connect(self.copy) self.layout.addWidget(self.button) def set_button_style(self, button, text, bg_color): self.pushButton.setText(text) stylesheet = f'background_color: {bg_color}' button.setText(text) button.setStyleSheet(stylesheet) def copy(self, MainWindow): self.set_button_style('WORKING...', 'rgb(250, 0, 0)') testprompt=storeid=pyautogui.prompt(text='test', title='test') self.set_button_style('SCAN', 'rgb(0, 250, 0)') if __name__ == '__main__': app = QtWidgets.Application(sys.argv) # use -stylesheet file to set styles mainwindow = MyCustomWindow('Window Title') mainwindow.show() sys.exit(app.exec_())