Reputation: 3493
I want to set cursor shape for QComboBox
and his items. With setCursor
affecting only LineEdit
part of QComboBox
, how do I access items view to change cursor shape?
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
we use Qt 5.5.1
Upvotes: 2
Views: 1035
Reputation: 2832
This code works:
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);
}
See Qt Event Filters
Upvotes: 3