Skip to content

Commit

Permalink
Multiselect combobox UX tweaks:
Browse files Browse the repository at this point in the history
- left clicking in the combo box opens the dropdown, just like a standard
combo box
- right clicking on an unexpanded combo shows the correct context menu
for the widget, instead of the default line edit context menu
  • Loading branch information
nyalldawson committed May 27, 2020
1 parent 4f7fcb3 commit 923072d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/gui/qgscheckablecombobox.cpp
Expand Up @@ -87,6 +87,9 @@ QgsCheckableComboBox::QgsCheckableComboBox( QWidget *parent )
pal.setBrush( QPalette::Base, pal.button() );
lineEdit->setPalette( pal );
setLineEdit( lineEdit );
lineEdit->installEventFilter( this );
lineEdit->setContextMenuPolicy( Qt::CustomContextMenu );
connect( lineEdit, &QAbstractItemView::customContextMenuRequested, this, &QgsCheckableComboBox::showContextMenu );

mContextMenu = new QMenu( this );
mSelectAllAction = mContextMenu->addAction( tr( "Select All" ) );
Expand Down Expand Up @@ -227,8 +230,16 @@ void QgsCheckableComboBox::deselectAllOptions()

bool QgsCheckableComboBox::eventFilter( QObject *object, QEvent *event )
{
if ( ( event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease )
&& object == view()->viewport() )
if ( object == lineEdit() )
{
if ( event->type() == QEvent::MouseButtonPress && static_cast<QMouseEvent *>( event )->button() == Qt::LeftButton && object == lineEdit() )
{
mSkipHide = true;
showPopup();
}
}
else if ( ( event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease )
&& object == view()->viewport() )
{
mSkipHide = true;

Expand Down

0 comments on commit 923072d

Please sign in to comment.