-
Notifications
You must be signed in to change notification settings - Fork 3
/
05_qhbox_qvbox_layouts.py
59 lines (45 loc) · 1.83 KB
/
05_qhbox_qvbox_layouts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QPushButton, QDialog, QGroupBox, QHBoxLayout, QVBoxLayout
class MainWindow(QDialog):
def __init__(self):
super().__init__()
self.title = "PyQt5 Layout Mgmt"
self.top = 500
self.left = 200
self.width = 400
self.height = 100
self.icon_name = "images/home.png"
self._init_window()
def _init_window(self):
self.setWindowIcon(QtGui.QIcon(self.icon_name))
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self._create_layout()
vbox = QVBoxLayout()
vbox.addWidget(self.group_box)
self.setLayout(vbox)
self.show()
def _create_layout(self):
self.group_box = QGroupBox("What is your favorite sport?")
hbox_layout = QHBoxLayout()
btn_soccer = QPushButton("Soccer", self)
btn_soccer.setIcon(QtGui.QIcon("images/soccer.png"))
btn_soccer.setIconSize(QtCore.QSize(30, 30))
btn_soccer.setMinimumHeight(40)
hbox_layout.addWidget(btn_soccer)
btn_basketball = QPushButton("Basketball", self)
btn_basketball.setIcon(QtGui.QIcon("images/basketball.png"))
btn_basketball.setIconSize(QtCore.QSize(30, 30))
btn_basketball.setMinimumHeight(40)
hbox_layout.addWidget(btn_basketball)
btn_tennis = QPushButton("Tennis", self)
btn_tennis.setIcon(QtGui.QIcon("images/tennis.png"))
btn_tennis.setIconSize(QtCore.QSize(30, 30))
btn_tennis.setMinimumHeight(40)
hbox_layout.addWidget(btn_tennis)
self.group_box.setLayout(hbox_layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())