我知道如何设计风格QComboBox
当鼠标悬停时执行以下操作:
pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox:hover{css style here}"))
我也知道风格QComboBox
的子控件向下箭头的样式通过:
pComboBox->setStyleSheet(pComboBox->styleSheet()+QString(" QComboBox::down-arrow{css style here}"))
但不知道怎么搭配QComboBox
的子控制down-arrow
当鼠标悬停在QComboBox
via QSS
。有人有想法吗?
我不知道是QSS
足够强大来做到这一点(我认为不是),但是eventfilter
你可以很容易地做到这一点:
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->comboBox && event->type() == QEvent::Enter)
{
//user enters combobox, so we apply stylesheet
ui->comboBox->setStyleSheet("QComboBox::down-arrow{background-color: red}");
}
else
if(event->type() == QEvent::Leave)//user leaves combobox, so we set default settings
ui->comboBox->setStyleSheet("");
return QObject::eventFilter(obj, event);
}
To use eventFilter
你还应该:
protected:
bool eventFilter(QObject *obj, QEvent *event);//in header
and
qApp->installEventFilter(this);//in constructor
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)