【发布时间】:2021-08-30 14:01:18
【问题描述】:
所以我在样式表中有一个名为main.qss 的Qt StyleSheet,我试图设置宽度和高度它不起作用它只是保持不变。 Margins 也会发生同样的情况。
这是 QSS:
QFrame#mainFrame {
background-color: #282C34;
}
QFrame#menuFrame {
background-color: #21252B;
}
QPushButton.menuButton {
background-color: #21252B;
padding-left: 12px;
padding-top: 1px;
padding-bottom: 1px;
border: 0;
font-family: "Times New Roman";
font-size: 20pt;
color: #FFFFFF;
width: 300pt; <-- Problem here
height: 15px; <-- Problem here
}
QPushButton.menuButton:hover {
background-color: #282C34;
}
QPushButton.menuButton:pressed {
background-color: #BD93F9;
}
这是我的 QPushButton:
self.menu_toggle_button = QtWidgets.QPushButton(self.menu_frame)
self.menu_toggle_button.setIcon(QtGui.QPixmap("menu_icons/menu.png"))
self.menu_toggle_button.setText(" Hide")
self.menu_toggle_button.setObjectName("menuToggleButton")
self.menu_toggle_button.setProperty("class", "menuButton")
self.menu_toggle_button.setIconSize(QtCore.QSize(20, 20))
那我做错了什么?
我知道这是可行的,因为在 Qt 样式表参考中,可以在这里找到:https://doc.qt.io/qtforpython-6/overviews/stylesheet-reference.html?highlight=stylesheet,它说 QPushButton 支持宽度、高度和边距。
【问题讨论】:
-
"它说 QPushButton 支持宽度、高度和边距。"你在哪里看到的?也许您指的是
max-width和min-width。实际上,width属性有一个明确的警告:“除非另有说明,否则在小部件上设置此属性时无效。” -
@musicamante 谢谢musicamante 这解决了我的宽度和高度问题,但是边距怎么办,因为这些仍然不起作用。
标签: python python-3.x pyside qtstylesheets pyside6