gpt4 book ai didi

c++ - 更改 QComboBox 项目的光标形状

转载 作者:搜寻专家 更新时间:2023-10-31 01:31:56 25 4
gpt4 key购买 nike

我想为 QComboBox 和他的项目设置光标形状。 setCursor 仅影响 QComboBoxLineEdit 部分,如何访问项目 View 以更改光标形状?

QComboBox *combo = new QComboBox();
combo->addItem("One");
combo->addItem("Two");
combo->addItem("Three");
combo->setCursor(Qt::PointingHandCursor); // changes cursor only for LineEdit part, on popup cursor is still arrow
combo->view()->setCursor(Qt::PointingHandCursor); // does not affect popup view

我们使用 Qt 5.5.1

最佳答案

此代码有效:

combo->installEventFilter(this);
//...

bool MainWin::eventFilter(QObject *obj, QEvent *ev)
{
if( obj == combo
&& (ev->type() == QEvent::Enter
|| ev->type() == QEvent::HoverMove) )
{
combo->setCursor(Qt::PointingHandCursor);
combo->view()->setCursor(Qt::PointingHandCursor);

return true;
}
return QMainWindow::eventFilter(obj, ev);
}

参见 Qt Event Filters

关于c++ - 更改 QComboBox 项目的光标形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44524871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com