示例代码
代码语言:python
代码运行次数:0
复制from __future__ import annotations
from PySide6.QtGui import QFont
from PySide6.QtWidgets import QApplication, QHBoxLayout, QLayout, QMainWindow, QPushButton, QScrollArea, QStyle, QVBoxLayout,
QWidget
class MyMainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('Hello, QStyle Icons!')
v_main_layout = QVBoxLayout()
count = 0
h_layout = QHBoxLayout()
for pixmap in QStyle.StandardPixmap:
button = QPushButton(pixmap.name, parent = self)
button.setFont(QFont('Ubuntu nf', 18))
style = button.style()
icon = style.standardIcon(pixmap)
button.setIcon(icon)
h_layout.addWidget(button)
count = 1
if count % 6 == 0:
v_main_layout.addLayout(h_layout)
count = 0
h_layout = QHBoxLayout()
if count > 0:
v_main_layout.addLayout(h_layout)
self.setCentralWidget(self.init_scroll_area(v_main_layout))
def init_scroll_area(self, layout: QLayout) -> QScrollArea:
colors_container = QWidget()
colors_container.setLayout(layout)
colors_scroll_area = QScrollArea(self)
colors_scroll_area.setWidgetResizable(True)
colors_scroll_area.setWidget(colors_container)
return colors_scroll_area
if __name__ == '__main__':
app = QApplication()
ins = MyMainWindow()
ins.show()
app.exec()
运行效果