Re: QListWidget read only
You can catch mouse events and suppress them when needed. This way the user can't select items but still will be able to scroll.
Re: QListWidget read only
Mouse events on QListWidget or on QListWidgetItem?
Re: QListWidget read only
Re: QListWidget read only
There's many ways you can get what you want.
If you need only mouse events to be ignored then you can use this:
Code:
this->list->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
This will not stop user from changing the selection using keyboard though.
To fully suppress user interaction with the widget install an event filter which will stop all mouse events on the viewport and keyboard events going to the widget:
Code:
MainWindow
::MainWindow(QWidget *parent
){
[...]// setup your lsit
this->list->installEventFilter( this );
this->list->viewport()->installEventFilter( this );
}
{
bool ret = false;
if( o == this->list &&
( e
->type
() == QEvent::KeyPress || e
->type
() == QEvent::KeyRelease ) ) {
qDebug() << "key";
ret = true;
}
else if( o == this->list->viewport() &&
( e
->type
() == QEvent::MouseButtonPress || e
->type
() == QEvent::MouseButtonPress || e
->type
() == QEvent::MouseButtonPress ) ) {
qDebug() << "mouse";
ret = true;
}
return ret;
}
Another way could be disabling the list widget and sticking it in separate scroll area.
Yet another would be setting NoSelection on the widget and providing custom item delegate which would draw item as 'selected' based on a property set on the item.
Re: QListWidget read only
Thank you Spitfire. it works with this modifications:
Code:
{
bool ret = false;
if( o == pListView &&
( e
->type
() == QEvent::KeyPress || e
->type
() == QEvent::KeyRelease ) ) {
qDebug() << "key";
ret = true;
}
else if( o == pListView->viewport() &&
( e
->type
() == QEvent::MouseButtonPress || e
->type
() == QEvent::MouseButtonRelease || e
->type
() == QEvent::MouseMove || e
->type
() == QEvent::MouseButtonDblClick ) ) {
qDebug() << "mouse";
ret = true;
}
return ret;
}
Re: QListWidget read only
or easy QAbstractItemView::setEventTrigger with QAbstractItemView::NoEditTriggers