更改 QComboBox 项的光标形状
Changing cursor shape for QComboBox items
我想为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
这段代码有效:
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事件过滤器
相关文章:
- 如何在Qt C++中更改光标
- 在QComboBox或QListWidget中设置所选元素的样式文本?
- 如何在QGridLayout中获取QComboBox的当前文本?
- Win32 API 控制台光标在 WriteConsole 后不移动
- 如何更改QComboBox项目的高度大小?
- 在 macOS 中使用 C/C++ 设置鼠标光标图像
- 如何更改输出的位置或光标在输出处,以便在"Code Blocks"中C++
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- 使用 C++将文本光标移动到屏幕中不可见的行
- 在 C# 中更改鼠标光标图标
- 错误:"类 QComboBox"没有名为"setCurrentText"的成员;
- ASCII 旋转光标 (TUI) 动画出现问题
- 将鼠标悬停在图片框上时,如何显示带有 x-y 坐标的十字准线光标?
- 将光标单独移动到当前位置
- 如何获得QTreeWidgetItem中QComboBox索引更改的通知?
- 如何获得鼠标光标连接时按下左键单击和在C++中释放左键单击时?
- 将 QList 转换为 QStringList 以插入到 QComboBox 中
- 更改 QComboBox 项的光标形状
- 当我按Enter或在其区域外单击鼠标时,如何从可编辑的Qcombobox中删除光标
- 信号编辑文本已更改为可编辑的QComboBox设置光标位置在设置编辑文本之后的末尾