QGridLayout strange widget placement - python

I am trying to build a simple GUI with PyQt5, where I have a few widgets which I want to align using QGridLayout.
Look at the following example code which I found on some website:
import sys
from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit,
QTextEdit, QGridLayout, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
title = QLabel('Title')
author = QLabel('Author')
review = QLabel('Review')
titleEdit = QLineEdit()
authorEdit = QLineEdit()
reviewEdit = QTextEdit()
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Output
As you can see, there are three labels in the first column, each spanning one cell vertically and one cell horizontally.
In the second column there are two 1x1 widgets and one 5x1 widget.
Let's say I want to place another label called test and a lineedit called testEdit below.
Naively I would modify initUI() like this:
def initUI(self):
title = QLabel('Title')
author = QLabel('Author')
review = QLabel('Review')
test = QLabel('Test')
titleEdit = QLineEdit()
authorEdit = QLineEdit()
reviewEdit = QTextEdit()
testEdit = QTextEdit()
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
grid.addWidget(test, 8, 0)
grid.addWidget(testEdit, 8, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show()
Where I just placed the new 1x1 widgets in the 8th row, below the previous one, which produces:
Output 2
However the result is not what I would expect, since the testEdit-widget is definitely not of size 1x1 and the reviewEdit-widget is also altered.
So why doesn't it work this way?

Try it:
import sys
from PyQt5.QtWidgets import (QWidget, QLabel, QLineEdit,
QTextEdit, QGridLayout, QApplication,
)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
title = QLabel('Title')
author = QLabel('Author')
review = QLabel('Review')
test = QLabel('Test')
titleEdit = QLineEdit()
authorEdit = QLineEdit()
reviewEdit = QTextEdit()
testEdit = QTextEdit()
testEdit.setMaximumHeight(20) # +++
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1)
grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1)
grid.addWidget(review, 3, 0)
grid.addWidget(reviewEdit, 3, 1, 5, 1)
grid.addWidget(test, 8, 0)
grid.addWidget(testEdit, 8, 1)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())

Related

why the QGridLayout do not work for QLabel

I am using QGridLayout in my project, and the code is:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=parent)
widget = QWidget()
self.setCentralWidget(widget)
layout = QGridLayout()
widget.setLayout(layout)
lay1 = QVBoxLayout()
lay1Header = QHBoxLayout()
lay1Header.addWidget(QLabel('lay1'))
lay1.addLayout(lay1Header)
label1 = QLabel('label1')
label1.setStyleSheet('background: rgb(255, 0, 0)')
lay1.addWidget(label1)
lay2 = QVBoxLayout()
lay2Header = QHBoxLayout()
lay2Header.addWidget(QLabel('lay2'))
lay2Header.addWidget(QLineEdit())
lay2.addLayout(lay2Header)
label2 = QLabel('label2')
label2.setStyleSheet('background: rgb(0, 0, 255)')
lay2.addWidget(label2)
layout.addLayout(lay1, 0, 0, 1, 1)
layout.addLayout(lay2, 0, 1, 1, 1)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
And the result is:
My environment is:
win 10
anaconda
pyqt5 5.14.0
How can I make the size of label1/label2 the same?
The size of the items in a QGridLayout depends on all the items in the column or row, not just one of them. So for this case the solution is to set the same alignment factor for the columns and set the height of the first QLabel to be that of the QLineEdit:
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=parent)
widget = QWidget()
self.setCentralWidget(widget)
layout = QGridLayout(widget)
lbl1 = QLabel("lay1")
lay1 = QVBoxLayout()
lay1Header = QHBoxLayout()
lay1Header.addWidget(lbl1)
lay1.addLayout(lay1Header)
label1 = QLabel("label1")
label1.setStyleSheet("background: rgb(255, 0, 0)")
lay1.addWidget(label1)
le1 = QLineEdit()
lay2 = QVBoxLayout()
lay2Header = QHBoxLayout()
lay2Header.addWidget(QLabel("lay2"))
lay2Header.addWidget(le1)
lay2.addLayout(lay2Header)
label2 = QLabel("label2")
label2.setStyleSheet("background: rgb(0, 0, 255)")
lay2.addWidget(label2)
layout.addLayout(lay1, 0, 0, 1, 1)
layout.addLayout(lay2, 0, 1, 1, 1)
layout.setColumnStretch(0, 1)
layout.setColumnStretch(1, 1)
lbl1.setFixedHeight(le1.sizeHint().height())

How to get an activeted lineEdit or label in pyQt

I'm trying to get a lineEdit that have a cursor in it when a button is clicked. For example: I run application, put a cursor in one lineEdit, and when clicking a button - some text should be set in chosen lineEdit.
I've tried with keyboardGrabber, but it returns button =None.
import sys
from PyQt5 import QtWidgets, QtCore
class Mainwindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("window")
self.lineEdit1 = QtWidgets.QLineEdit()
self.lineEdit2 = QtWidgets.QLineEdit()
self.lineEdit3 = QtWidgets.QLineEdit()
self.pushButton = QtWidgets.QPushButton()
self.label = QtWidgets.QLabel()
self.label.setText('#1')
self.frame = QtWidgets.QFrame(self)
self.frame.setGeometry(QtCore.QRect(0, 0, 200, 100))
self.gridLayout = QtWidgets.QGridLayout(self.frame)
self.gridLayout.addWidget(self.lineEdit1, 0, 0, 1, 1)
self.gridLayout.addWidget(self.lineEdit2, 0, 1, 1, 1)
self.gridLayout.addWidget(self.lineEdit3, 0, 2, 1, 1)
self.gridLayout.addWidget(self.label, 0, 3, 1, 1)
self.gridLayout.addWidget(self.pushButton, 1, 0, 1, 1)
self.pushButton.clicked.connect(self.function)
def function(self):
widget = self.keyboardGrabber()
widget.setText('some text')
if __name__ == '__main__':
app = QtWidgets.QApplication([])
application = Mainwindow()
application.show()
Try it: void QApplication::focusChanged(QWidget *old, QWidget *now)
This signal is emitted when the widget that has keyboard focus changed from old to now, i.e., because the user pressed the tab-key, clicked into a widget or changed the active window. Both old and now can be nullptr.
import sys
from PyQt5 import QtWidgets, QtCore
class Mainwindow(QtWidgets.QMainWindow): # QMainWindow QWidget
def __init__(self):
super().__init__()
QtWidgets.qApp.focusChanged.connect(self.on_focusChanged) # +++
self.setWindowTitle("window")
self.lineEdit1 = QtWidgets.QLineEdit(self)
self.lineEdit1.setFocus() # +
self.lineEdit2 = QtWidgets.QLineEdit()
self.lineEdit3 = QtWidgets.QLineEdit()
self.pushButton = QtWidgets.QPushButton()
self.label = QtWidgets.QLabel()
self.label.setText('#1')
self.frame = QtWidgets.QFrame(self)
self.setCentralWidget(self.frame) # +
self.frame.setGeometry(QtCore.QRect(0, 0, 200, 100))
self.gridLayout = QtWidgets.QGridLayout(self.frame)
self.gridLayout.addWidget(self.lineEdit1, 0, 0, 1, 1)
self.gridLayout.addWidget(self.lineEdit2, 0, 1, 1, 1)
self.gridLayout.addWidget(self.lineEdit3, 0, 2, 1, 1)
self.gridLayout.addWidget(self.label, 0, 3, 1, 1)
self.gridLayout.addWidget(self.pushButton, 1, 0, 1, 1)
self.lineFocus = ... # +++
self.pushButton.clicked.connect(self.function)
def function(self):
# widget = self.keyboardGrabber()
# widget.setText('some text')
self.lineFocus.setText('some text')
#QtCore.pyqtSlot("QWidget*", "QWidget*")
def on_focusChanged(self, old, now): # +++
#print(f"\nold: {old}, now: {now}")
self.lineFocus = old
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
application = Mainwindow()
application.show()
sys.exit(app.exec_())

How to check if a RadioButton was checked from another class?

I'm making a GUI in PyQt5 where there are multiple tabs. In one of the tabs, users select a radio button with what type of data they are entering.
This information changes what buttons are available in other tabs and I'm having trouble getting this information passed from the original tab class. I'd like to see if a radio button is checked from another tab and if it is, enable a button.
I have a function to return a string depending on which radio button is selected, but when I call the getDataType() function from the other tab, I get the error "AttributeError: module 'DataTab' has no attribute 'getDataType.'"
I've tried moving the getDataType() function outside of the DataTab class, but since the radio buttons use "self," I'm not able to access them.
I've also tried making a new class and calling that new class from the function, but then I get stuck on how to get the information to my other tab.
So in this example, once a user selects a radio button in the Data Tab, I want the corresponding push button on the Analysis Tab enabled.
When I uncomment the call to getDataType(), I get the following error: "AttributeError: module 'DataTab' has no attribute 'getDataType'"
from PyQt5.QtWidgets import (QWidget, QVBoxLayout, QLabel, QTableWidget, QTableWidgetItem,
QLineEdit, QFileDialog, QRadioButton, QGroupBox, QPushButton,
QGridLayout, QButtonGroup, QApplication, QAbstractItemView,
QTabWidget)
from PyQt5.QtGui import QIcon
import sys, os
class TabPage(QTabWidget):
def __init__(self):
super().__init__()
self.setStyleSheet('font: 15pt Tw Cen MT')
self.show()
# Creating the tabs here to have a reference
self.tabWidget = QTabWidget()
self.tabWidget.addTab(DataTab(), "Data Input")
self.tabWidget.addTab(AnalysisTab(), "Analysis")
self.layout = QVBoxLayout()
self.layout.addWidget(self.tabWidget)
self.setLayout(self.layout)
# The DataTab class holds all the GUI for the DataTab
class DataTab(QWidget):
def __init__(self):
super().__init__()
self.app = QApplication(sys.argv)
self.layout = QGridLayout()
self.intervalRadioButton = QRadioButton("Interval")
self.ordinalRadioButton = QRadioButton("Ordinal")
self.frequencyRadioButton = QRadioButton("Frequency")
self.submitButton = QPushButton("Submit Data")
self.layout.addWidget(self.intervalRadioButton, 7, 0, 1, 3)
self.layout.addWidget(self.ordinalRadioButton, 8, 0, 1, 3)
self.layout.addWidget(self.frequencyRadioButton, 9, 0, 1, 3)
self.setLayout(self.layout)
self.show()
def getDataType(self):
if self.intervalRadioButton.isChecked():
return "interval"
elif self.ordinalRadioButton.isChecked():
return "ordinal"
elif self.frequencyRadioButton.isChecked():
return "frequency"
class AnalysisTab(QWidget):
def __init__(self):
super().__init__()
self.app = QApplication(sys.argv)
self.createChooseIntervalGroup()
self.createChooseOrdinalGroup()
self.createChooseFrequencyGroup()
self.layout = QGridLayout()
self.layout.addWidget(self.ChooseIntervalGroup, 0, 1)
self.layout.addWidget(self.ChooseOrdinalGroup, 1, 1)
self.layout.addWidget(self.ChooseFrequencyGroup, 2, 1)
self.setLayout(self.layout)
self.show()
# The right side of AnalysisTab containing the buttons for
# analysis
def createChooseIntervalGroup(self):
self.ChooseIntervalGroup = QGroupBox("Tests for Interval Data")
self.analyzeIntervalButton = QPushButton("Analyze")
self.analyzeIntervalButton.setEnabled(False)
# if DataTab.getDataType() != "interval":
# self.analyzeIntervalButton.setEnabled(True)
self.layout = QGridLayout()
self.layout.addWidget(self.analyzeIntervalButton, 1, 1)
self.ChooseIntervalGroup.setLayout(self.layout)
# The right side of AnalysisTab containing the buttons for
# analysis
def createChooseOrdinalGroup(self):
self.ChooseOrdinalGroup = QGroupBox("Tests for Ordinal Data")
self.analyzeOrdinalButton = QPushButton("Analyze")
self.analyzeOrdinalButton.setEnabled(False)
# if DataTab.getDataType() != "ordinal":
# self.analyzeIntervalButton.setEnabled(True)
self.layout = QGridLayout()
self.layout.addWidget(self.analyzeOrdinalButton, 1, 1)
self.ChooseOrdinalGroup.setLayout(self.layout)
# The right side of AnalysisTab containing the buttons for
# analysis
def createChooseFrequencyGroup(self):
self.ChooseFrequencyGroup = QGroupBox("Tests for Frequency Data")
self.analyzeFrequencyButton = QPushButton("Analyze")
self.analyzeFrequencyButton.setEnabled(False)
# if DataTab.getDataType() != "frequency":
# self.analyzeIntervalButton.setEnabled(True)
self.layout = QGridLayout()
self.layout.addWidget(self.analyzeFrequencyButton, 1, 1)
self.ChooseFrequencyGroup.setLayout(self.layout)
def run():
app = QApplication(sys.argv)
tabPage = TabPage()
tabPage.show()
app.exec_()
run()
A possible solution for this case is to use the signals to notify the change of status of the QRadioButton to enable or disable the button.
import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import (
QWidget,
QVBoxLayout,
QRadioButton,
QGroupBox,
QPushButton,
QGridLayout,
QButtonGroup,
QApplication,
QTabWidget,
)
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setStyleSheet("font: 15pt Tw Cen MT")
self.data_tab = DataTab()
self.analysis_tab = AnalysisTab()
self.tabWidget = QTabWidget()
self.tabWidget.addTab(self.data_tab, "Data Input")
self.tabWidget.addTab(self.analysis_tab, "Analysis")
layout = QVBoxLayout(self)
layout.addWidget(self.tabWidget)
self.data_tab.intervalRadioButton.toggled.connect(
self.analysis_tab.analyzeIntervalButton.setEnabled
)
self.data_tab.ordinalRadioButton.toggled.connect(
self.analysis_tab.analyzeOrdinalButton.setEnabled
)
self.data_tab.frequencyRadioButton.toggled.connect(
self.analysis_tab.analyzeFrequencyButton.setEnabled
)
class DataTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = QGridLayout(self)
self.intervalRadioButton = QRadioButton("Interval")
self.ordinalRadioButton = QRadioButton("Ordinal")
self.frequencyRadioButton = QRadioButton("Frequency")
self.submitButton = QPushButton("Submit Data")
layout.addWidget(self.intervalRadioButton, 7, 0, 1, 3)
layout.addWidget(self.ordinalRadioButton, 8, 0, 1, 3)
layout.addWidget(self.frequencyRadioButton, 9, 0, 1, 3)
class AnalysisTab(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.createChooseIntervalGroup()
self.createChooseOrdinalGroup()
self.createChooseFrequencyGroup()
layout = QGridLayout(self)
layout.addWidget(self.ChooseIntervalGroup, 0, 1)
layout.addWidget(self.ChooseOrdinalGroup, 1, 1)
layout.addWidget(self.ChooseFrequencyGroup, 2, 1)
def createChooseIntervalGroup(self):
self.ChooseIntervalGroup = QGroupBox("Tests for Interval Data")
self.analyzeIntervalButton = QPushButton("Analyze")
self.analyzeIntervalButton.setEnabled(False)
layout = QGridLayout(self.ChooseIntervalGroup)
layout.addWidget(self.analyzeIntervalButton, 1, 1)
def createChooseOrdinalGroup(self):
self.ChooseOrdinalGroup = QGroupBox("Tests for Ordinal Data")
self.analyzeOrdinalButton = QPushButton("Analyze")
self.analyzeOrdinalButton.setEnabled(False)
layout = QGridLayout(self.ChooseOrdinalGroup)
layout.addWidget(self.analyzeOrdinalButton, 1, 1)
def createChooseFrequencyGroup(self):
self.ChooseFrequencyGroup = QGroupBox("Tests for Frequency Data")
self.analyzeFrequencyButton = QPushButton("Analyze")
self.analyzeFrequencyButton.setEnabled(False)
layout = QGridLayout(self.ChooseFrequencyGroup)
layout.addWidget(self.analyzeFrequencyButton, 1, 1)
def run():
app = QApplication(sys.argv)
tabPage = Widget()
tabPage.show()
app.exec_()
run()

Pyqt QSplitter not visualizing correctly

I'm trying to incorporate a QSplitter. The code works perfectly from a functionality standpoint, but the QSplitter itself doesn't appear correctly under the default PyQt style... possibly because it is itself embedded within a vertical splitter. This is confusing for the user.
If you uncomment out the line (and thus change the default PyQt style), the QSplitter visualizes correctly only when hovered over... however, I also don't want this other style.
Can anyone provide any guidance on this matter?
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
L_layout = QGridLayout()
R_layout = QGridLayout()
L_widgets = QWidget()
L_widgets.setLayout(L_layout)
R_widgets = QWidget()
R_widgets.setLayout(R_layout)
topleft = QFrame()
topleft.setFrameShape(QFrame.StyledPanel)
btn1 = QPushButton('btn1')
bottom = QFrame()
bottom.setFrameShape(QFrame.StyledPanel)
textedit = QTextEdit()
L_layout.addWidget(topleft, 0, 0, 1, 1)
L_layout.addWidget(btn1, 1, 0, 1, 1)
R_layout.addWidget(textedit)
splitter1 = QSplitter(Qt.Horizontal,frameShape=QFrame.StyledPanel,frameShadow=QFrame.Plain)
splitter1.addWidget(L_widgets)
splitter1.addWidget(R_widgets)
splitter1.setStretchFactor(1,1)
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
#QApplication.setStyle(QStyleFactory.create('Cleanlooks'))
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QSplitter demo')
self.show()
def main():
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
EDIT: This is apparently a known macOS bug. When viewed on Linux, the bar of splitter1 has the same look as splitter2. I'll leave this topic open in case anyone else knows of a suitable workaround for mac.
Because the QPushButton has default minimum size, when you want to move splitter to left,
the button has reached its minimum size. So you can not move left anymore, otherwise the left will will collapse.
So if you want the left showing as you want, you can set the minimum size off button widget.
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
L_layout = QGridLayout()
R_layout = QGridLayout()
L_widgets = QWidget()
L_widgets.setLayout(L_layout)
R_widgets = QWidget()
R_widgets.setLayout(R_layout)
topleft = QFrame()
topleft.setFrameShape(QFrame.StyledPanel)
btn1 = QPushButton('btn1')
btn1.setMinimumWidth(1) # For example : set the minimum width to 1, then you can move left until the btn1 width is 1
bottom = QFrame()
bottom.setFrameShape(QFrame.StyledPanel)
textedit = QTextEdit()
L_layout.addWidget(topleft, 0, 0, 1, 1)
L_layout.addWidget(btn1, 1, 0, 1, 1)
R_layout.addWidget(textedit)
splitter1 = QSplitter(Qt.Horizontal,frameShape=QFrame.StyledPanel,frameShadow=QFrame.Plain)
splitter1.addWidget(L_widgets)
splitter1.addWidget(R_widgets)
splitter1.setStretchFactor(1,1)
splitter2 = QSplitter(Qt.Vertical)
splitter2.addWidget(splitter1)
splitter2.addWidget(bottom)
hbox.addWidget(splitter2)
self.setLayout(hbox)
#QApplication.setStyle(QStyleFactory.create('Cleanlooks'))
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QSplitter demo')
self.show()
def main():
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

PySide (Qt) - Layout not working

I am trying to create a simple application with PySide, but it seems that I didn't read the docs properly. That is my code:
from PySide.QtGui import *
from PySide.QtCore import Qt
class Window(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.scene = QGraphicsScene()
self.view1 = QGraphicsView(self.scene, self)
self.view2 = QGraphicsView(self.scene, self)
self.gridLayout = QGridLayout()
self.gridLayout.addWidget(self.view1, 0, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.view2, 0, 1, Qt.AlignRight)
self.gridLayout.setColumnMinimumWidth(0, 300)
self.gridLayout.setColumnMinimumWidth(1, 300)
self.setLayout(self.gridLayout)
self.view1.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.view2.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.scene.addLine(0, 0, 1000, 1000)
if __name__ == "__main__":
app = QApplication(())
window = Window()
window.showMaximized()
app.exec_()
The code executes, but it should display a window with two QGraphicsViews, which should divide the window in half, but I only get one QGraphicsView in its minimum size. Can someone help me with this?
Thanks in advance.
You need to create a central widget for a QMainWindow, and then set the layout on that. Simplifying your example:
from PySide.QtGui import *
class Window(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.scene = QGraphicsScene()
self.view1 = QGraphicsView(self.scene, self)
self.view2 = QGraphicsView(self.scene, self)
self.view1.setFrameShape(QFrame.NoFrame)
self.view2.setFrameShape(QFrame.NoFrame)
widget = QWidget(self)
layout = QGridLayout(widget)
layout.addWidget(self.view1, 0, 0)
layout.addWidget(self.view2, 0, 1)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
self.setCentralWidget(widget)
self.scene.addLine(0, 0, 1000, 1000)
if __name__ == "__main__":
app = QApplication(())
window = Window()
window.showMaximized()
app.exec_()

Categories

Resources