import sys
from PyQt5.Qt import *
from qss import Qss
class Window(QWidget):
def __init__(self):
super().__init__()
self.setup_ui()
def setup_ui(self):
self.setWindowTitle("Qt桌面应用程序")
self.resize(1200, 600)
self.main_box_layout = QHBoxLayout()
self.setLayout(self.main_box_layout)
self.size_policy = QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
self.push_button = QPushButton("按钮")
self.push_button.setObjectName("push_button")
self.push_button.setSizePolicy(self.size_policy)
self.label = QLabel()
self.label.setMinimumSize(300, 300)
self.label.setSizePolicy(self.size_policy)
self.label.setText("你好,世界!")
self.text_edit = QTextEdit()
self.text_edit.setLineWrapMode(QTextEdit.NoWrap)
self.text_edit.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.text_edit.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.text_edit.setMinimumSize(300, 300)
self.text_edit.setSizePolicy(self.size_policy)
self.text_edit.setPlaceholderText("多行文本框...")
self.spin_box = QSpinBox()
self.spin_box.setMinimumSize(200, 100)
self.spin_box.setSizePolicy(self.size_policy)
self.box_layout = QVBoxLayout()
self.box_layout.addWidget(self.push_button)
self.box_layout.addWidget(self.label)
self.box_layout.addWidget(self.text_edit)
self.box_layout.addWidget(self.spin_box)
self.box_layout_2 = QGridLayout()
self.box_layout_2.setAlignment(Qt.AlignTop)
for i in range(55):
self.image_push_button = QPushButton()
self.image_push_button.setFixedSize(53, 70)
self.image_push_button.setStyleSheet("""
QPushButton {
padding: %dpx 0 0 %dpx;
background-image:url(puke.png);
background-origin: content;
background-clip: padding;
}""" % (int(-(i // 13) * 66), int(-(i % 13) * 49)))
self.box_layout_2.addWidget(self.image_push_button, i // 13, i % 13)
self.main_box_layout.addLayout(self.box_layout)
self.main_box_layout.addLayout(self.box_layout_2, 1)
Qss.set_qss(self, "qss.qss")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
/*
border-image: url(border_test_num.png) 30 30 30 30 stretch;
min-width: 300;
min-height: 300;
QWidget QWidget {
border-width: 10px;
border-color: green;
border-style: double solid dashed dotted;
border-top-left-radius: 100;
margin: 10 16 10 16;
padding: 10 16 10 16;
background-color: cyan;
background-origin: border;
background-clip: padding;
background-position: top right;
background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0 OrangeRed, stop: 0.5 gray, stop: 1 yellow);
background: qradialgradient(cx:0.5, cy:0.5, radius:0.7, fx:0.7,fy:0.7, stop: 0 OrangeRed, stop: 0.5 gray, stop: 1 yellow);
background: qconicalgradient(cx:0.5, cy:0.5, angle:30, stop: 0 OrangeRed, stop: 0.5 gray, stop: 1 yellow);
font-style: italic;
font-family: LiSu;
font-size: 30px;
font-weight: 900;
color: red;
}
QPushButton:enabled {
color: Coral;
}
QPushButton:hover {
color: DarkTurquoise;
}
*/
Window {
background-color:LightBLue;
}
QPushButton {
color: Coral;
}
QAbstractButton {
color: DarkTurquoise;
}
QSpinBox::up-button {
subcontrol-position: left;
}
QSpinBox::up-button:hover {
subcontrol-position: left;
top:5px;
}
QSpinBox::down-button {
subcontrol-position: right;
}
QSpinBox::down-button:hover {
subcontrol-position: right;
top:5px;
}