【发布时间】:2013-02-08 18:55:01
【问题描述】:
我在输入表单上有一个可编辑组合框,当它获得焦点时,它的背景必须改变。以下代码适用于 QLineEdit,但对 QComboBox 无效。
QLineEdit, QComboBox { background-color: green; }
QLineEdit:focus, QComboBox:focus { background-color: red; }
是否有可能使 QComboBox 像 QLineEdit 一样仅使用 Qt 样式表?
【问题讨论】:
-
试试 QComboBox:!editable:focus
-
好问题!我能够通过
setStyleSheet("QLineEdit, QComboBox { background-color: green; }" "QComboBox:focus, QComboBox:focus QListView { background-color: red; }");到达某个地方,但似乎我错过了一些东西...... -
即使设置这个工作,但不是背景
setStyleSheet("QLineEdit, QComboBox { background-color: green; }" "QComboBox:focus, QComboBox:focus QAbstractItemView { background-color: red; selection-background-color: red}"); -
@RachelGallen 在问这里之前我已经尝试过了。
-
@NemanjaBoric:是的,我也试过了,但它只会改变所选文本的背景颜色。此外,当我使用
QComboBox { background-color: transparent; }时,我的:focus开始工作,但我失去了失焦背景。输入padding: 2会提供一些额外的信息——组合框前面有一些东西。它应该是QLineEdit,但它不是,或者不完全是。我试过QComboBox > QLineEdit没有成功。