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

标签 c++ qt qt5 qcombobox qcursor

我想为 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/

相关文章:

c++ - 处理 tcp/udp 接收的最佳方式。

c++ - 为什么 std::vector 零初始化它的内存?

c++ - 为什么我的窗口没有显示任何 QPixmap 图片?

qt - Qt 5.10程序可以在XP上运行吗?

qt - QJsonValue 的转换方法始终返回其默认值

c++ - 为什么 vkCreateSwapchainKHR 会在 0 处导致访问冲突?

C++ 概念 访问公共(public)方法

c++ - 错误 : no match for ‘operator*’ (operand types are ‘QGenericMatrix<4, 4, float>’ and ‘QGenericMatrix<4, 3, float>’ )

qt - 如何将具有自定义属性的组件移动到 QML 中的单独文件

c++ - 关于connect的新手QT问题