Skip to content
Permalink
Browse files

[options search] do not show widget when text is found (#6052)

fix #17812
  • Loading branch information
3nids committed Jan 12, 2018
1 parent 2156b5a commit 8074dc4cbf21f4415f61cc819faf0fa54dc7c855
Showing with 46 additions and 8 deletions.
  1. +3 −0 python/gui/qgsoptionsdialogbase.sip
  2. +40 −8 src/gui/qgsoptionsdialogbase.cpp
  3. +3 −0 src/gui/qgsoptionsdialogbase.h
@@ -58,6 +58,9 @@ reset the style to the original state
return the widget
%End

virtual bool eventFilter( QObject *obj, QEvent *event );


};


@@ -464,23 +464,55 @@ bool QgsSearchHighlightOptionWidget::searchHighlight( const QString &searchText
if ( !mWidget->isVisible() )
{
// show the widget to get initial stylesheet in case it's modified
mWidget->show();
QgsDebugMsg( QString( "installing event filter on: %1 (%2)" )
.arg( mWidget->objectName() )
.arg( qobject_cast<QLabel *>( mWidget ) ? qobject_cast<QLabel *>( mWidget )->text() : QString() ) );
mWidget->installEventFilter( this );
mInstalledFilter = true;
}
else
{
mWidget->setStyleSheet( mWidget->styleSheet() + mStyleSheet );
mChangedStyle = true;
}
mWidget->setStyleSheet( mWidget->styleSheet() + mStyleSheet );
mChangedStyle = true;
}

return found;
}

bool QgsSearchHighlightOptionWidget::eventFilter( QObject *obj, QEvent *event )
{
if ( mInstalledFilter && event->type() == QEvent::Show && obj == mWidget )
{
removeEventFilter( mWidget );
mInstalledFilter = false;
mWidget->show();
//QTimer::singleShot( 500, this, [ = ]
//{
mWidget->setStyleSheet( mWidget->styleSheet() + mStyleSheet );
mChangedStyle = true;
//} );
return true;
}
return QObject::eventFilter( obj, event );
}

void QgsSearchHighlightOptionWidget::reset()
{
if ( mWidget && mValid && mChangedStyle )
if ( mWidget && mValid )
{
QString ss = mWidget->styleSheet();
ss.remove( mStyleSheet );
mWidget->setStyleSheet( ss );
mChangedStyle = false;
if ( mChangedStyle )
{
QString ss = mWidget->styleSheet();
ss.remove( mStyleSheet );
mWidget->setStyleSheet( ss );
mChangedStyle = false;
}
else if ( mInstalledFilter )
{
removeEventFilter( mWidget );
mInstalledFilter = false;
}
}
}

@@ -80,6 +80,8 @@ class GUI_EXPORT QgsSearchHighlightOptionWidget : public QObject
*/
QWidget *widget() { return mWidget; }

bool eventFilter( QObject *obj, QEvent *event ) override;

private slots:
void widgetDestroyed();

@@ -89,6 +91,7 @@ class GUI_EXPORT QgsSearchHighlightOptionWidget : public QObject
bool mValid = true;
bool mChangedStyle = false;
std::function < QString() > mText;
bool mInstalledFilter = false;
};


0 comments on commit 8074dc4

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