【发布时间】:2015-09-24 09:43:57
【问题描述】:
在 Qt 应用程序中,我有一个按钮,稍后我会使用一些代码将菜单附加到它。菜单的每个元素都是可检查的QAction。有趣的是,一旦元素被检查,检查标志是不可见的,除非你用鼠标悬停它。这是截图:
我有一些自定义的 QCSS 集,但是,我从来没有为 QAction 或任何东西添加任何样式,这里是:
QMainWindow, QDialog { background: #E8E8E8; color: #2e2e2e; }
QMenuBar, QStatusBar {
background: #545454;
color: #fff;
}
QLabel#lblBanner {
background: qlineargradient(x1: 0, y1: 0.01, x2: 0, y2: 1,
stop: 0 #545454, stop: 1 #141414);
margin: 0;
}
QMenu {
background: #E8E8E8;
}
QMenuBar::item {
background: transparent;
}
QMenuBar::item:selected {
background: #444442;
border: 0;
}
QMenuBar::item:pressed {
background: #444442;
}
QMenu::item:selected {
background: #cfcfcf;
}
QGroupBox {
background: #fff;
/* border: 1px solid white; */
border-radius: 5px;
margin: 3px 3px 3px 3px;
padding: 18px 5px 10px 5px;
font-weight: bold;
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
color: black;
font-style: bold;
/* padding: 4px 5px; */
margin-left: 6px;
margin-top: 7px;
background: transparent;
color: #2e2e2e;
}
QPushButton, QDialogButtonBox {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f5f5f5, stop: 1 #cfcfcf);
border-radius: 3px;
padding: 5px 10px;
margin: 1px;
min-width: 30px ;
}
QPushButton:hover, QDialogButtonBox:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #cfcfcf, stop: 1 #b5b5b5);
}
QPushButton:pressed, QDialogButtonBox:pressed {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #b5b5b5, stop: 1 #cfcfcf);
}
QPushButton:default, QDialogButtonBox:default {
border: 1px solid;
border-color: orange; /* make the default button prominent */
}
QPushButton[enabled=false]
{
background: #ededed;
color: #cfcfcf;
}
QLineEdit, QTextEdit {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.3,
stop: 0 #f2f2f2, stop: 1 white);
border: 2px solid #E8E8E8;
selection-background-color: orange;
border-radius: 5px;
padding: 3px;
}
QHeaderView::section {
background-color: qlineargradient(x1: 0, y1: 0.01, x2: 0, y2: 1,
stop: 0 #545454, stop: 1 #141414);
color: white;
padding-left: 10px;
border: 1px solid #6c6c6c;
}
QTreeWidget {
border: 2px solid #E8E8E8;
border-radius: 5px;
selection-background-color: orange;
show-decoration-selected: 1;
}
/* QTreeWidget::item:selected { */
/* background: ; */
/* } */
QTreeWidget::item:selected:!active {
background: #e59500;
}
QTreeWidget::item:selected:active {
background: #f29d00;
}
QTreeWidget::item:hover {
background: orange;
}
QTreeWidget::branch {
background: white;
}
/* barra de desplazamiento */
/* Vertical */
QScrollBar:vertical {
background: #fff;
width: 10px;
}
QScrollBar::handle:vertical {
background: #E8E8E8;
}
/* Horizontal */
QScrollBar:horizontal {
background: #fff;
height: 10px;
}
QScrollBar::handle:horizontal {
background: #E8E8E8;
}
/* Fin de la barra de desplazamiento */
QProgressBar {
border: 2px solid orange;
border-radius: 5px;
background: #fff;
text-align: center;
}
QProgressBar::chunk {
background: orange;
margin: 2px;
border-radius: 5px;
}
可能是什么问题,我可以通过什么方式解决这个问题?
【问题讨论】:
-
去掉自定义CSS还有问题吗?
-
@tmoreau 一点也不!会是什么?
-
@tmoreau 啊!如果指定了
QMenu {background: #E8E8E8;},就会出现问题!