Skip to content

Commit addf358

Browse files
committed
Imported Qt classes from its modules.
Because that's how I've seen people write PyQt applications. Plus, the package appears to be designed to be imported like that. Window title set correctly on Windows. (It doesn't automatically set it using the arguments of `QApplication`.)
1 parent 9238332 commit addf358

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

examples/examples_ScrollableAreaQt5.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#! /usr/bin/python3 -B
22

33
import itertools
4-
import PyQt5.QtCore as QtCore
5-
import PyQt5.QtWidgets as QtWidgets
4+
from PyQt5.QtCore import QSize
5+
from PyQt5.QtWidgets import QApplication, QGridLayout, QLabel, QMainWindow, QVBoxLayout
66

77
from ScrollableContainers.Qt5 import ScrollableAreaQt5
88

99
###############################################################################
1010

1111
def grid_of_widgets():
12-
app = QtWidgets.QApplication(['`ScrollableAreaQt5` demo'])
13-
window = QtWidgets.QMainWindow()
12+
app = QApplication([])
13+
window = QMainWindow()
14+
window.setWindowTitle('`ScrollableAreaQt5` demo')
1415

1516
# Create a scrollable area.
1617
scrollable_area = ScrollableAreaQt5()
1718

1819
# Add widgets to the `area` attribute of the scrollable area, not to the
1920
# scrollable area itself.
2021
dim = 10
21-
grid_layout = QtWidgets.QGridLayout(scrollable_area.area)
22+
grid_layout = QGridLayout(scrollable_area.area)
2223
for (i, j) in itertools.product(range(dim), repeat=2):
23-
grid_layout.addWidget(QtWidgets.QLabel(text=f'Label\n({i}, {j})'), i, j)
24+
grid_layout.addWidget(QLabel(text=f'Label\n({i}, {j})'), i, j)
2425

2526
window.setCentralWidget(scrollable_area)
2627
window.show()
@@ -29,13 +30,14 @@ def grid_of_widgets():
2930
###############################################################################
3031

3132
def single_widget():
32-
app = QtWidgets.QApplication(['`ScrollableAreaQt5` demo'])
33-
window = QtWidgets.QMainWindow(size=QtCore.QSize(600, 200))
33+
app = QApplication([])
34+
window = QMainWindow(size=QSize(600, 200))
35+
window.setWindowTitle('`ScrollableAreaQt5` demo')
3436

3537
scrollable_area = ScrollableAreaQt5()
3638

37-
vbox = QtWidgets.QVBoxLayout(scrollable_area.area)
38-
vbox.addWidget(QtWidgets.QLabel(text='big window, small label'))
39+
vbox = QVBoxLayout(scrollable_area.area)
40+
vbox.addWidget(QLabel(text='big window, small label'))
3941

4042
window.setCentralWidget(scrollable_area)
4143
window.show()

src/ScrollableContainers/Qt5.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
__all__ = ['ScrollableAreaQt5']
22

3-
import PyQt5.QtCore as QtCore
4-
import PyQt5.QtWidgets as QtWidgets
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import QScrollArea, QVBoxLayout, QWidget
55

66

7-
class ScrollableAreaQt5(QtWidgets.QScrollArea):
7+
class ScrollableAreaQt5(QScrollArea):
88
"""
99
Container with horizontal and vertical scrolling capabilities. Widgets must be
1010
added to its `area` attribute.
@@ -14,10 +14,10 @@ def __init__(self, *args, **kwargs):
1414
super().__init__(*args, **kwargs)
1515

1616
# This object only allows a container to be placed in it.
17-
container = QtWidgets.QWidget()
17+
container = QWidget()
1818
self.setWidget(container)
19-
vbox = QtWidgets.QVBoxLayout(container)
20-
self.area = QtWidgets.QWidget()
21-
vbox.addWidget(self.area, alignment=QtCore.Qt.AlignHCenter)
19+
vbox = QVBoxLayout(container)
20+
self.area = QWidget()
21+
vbox.addWidget(self.area, alignment=Qt.AlignHCenter)
2222
vbox.addStretch()
2323
self.setWidgetResizable(True)

0 commit comments

Comments
 (0)