2

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

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

4

1 回答 1

3

此代码有效:

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 事件过滤器

于 2017-06-13T15:22:24.317 回答