所以我在样式表中调用了一个 Qt StyleSheetmain.qss
我试图设置宽度和高度它不起作用它只是保持不变。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 支持边距。