Skip to content
Permalink
Browse files

Multiselect combobox UX tweaks:

- 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 923072d9e92a228e67bfaf3ef8936104264b7432
Showing with 13 additions and 2 deletions.
  1. +13 −2 src/gui/qgscheckablecombobox.cpp
@@ -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" ) );
@@ -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;

0 comments on commit 923072d

Please sign in to comment.
You can’t perform that action at this time.