There's many ways you can get what you want.
If you need only mouse events to be ignored then you can use this:
this->list->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
this->list->viewport()->setAttribute( Qt::WA_TransparentForMouseEvents );
To copy to clipboard, switch view to plain text mode
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:
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;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
list = new QListWidget( this );
[...]// setup your lsit
this->list->installEventFilter( this );
this->list->viewport()->installEventFilter( this );
}
bool MainWindow::eventFilter( QObject* o, QEvent* e )
{
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;
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks