C++ (Qt)bool YourListWidget::event( QEvent *event ){ switch( event->type() ) { case QEvent::HoverEnter: setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); break; case QEvent::HoverLeave: setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); break; default: break; } return QListWidget::event( event );}
C++ (Qt)#include <QtGui> class CListLegend: public QListWidget{ Q_OBJECTpublic: CListLegend(QWidget *parent):QListWidget(parent) { setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } bool event(QEvent * ev) { switch( ev->type() ) { case QEvent::HoverEnter: setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); break; case QEvent::HoverLeave: setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); break; default: break; } return QListWidget::event( ev ); } };
Clist = new CListLegend (this); list->move(10,10); list->addItems(QStringList()<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf"<<"sfdsdfsdf"<<"sdf");
C++ (Qt)CListLegend(QWidget *parent):QListWidget(parent){ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSelectionMode(QAbstractItemView::SelectionMode::NoSelection); blockSignals(true);}