Skip to content

Commit

Permalink
[options search] do not show widget when text is found (#6052)
Browse files Browse the repository at this point in the history
fix #17812
  • Loading branch information
3nids authored Jan 12, 2018
1 parent 2156b5a commit 8074dc4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
3 changes: 3 additions & 0 deletions python/gui/qgsoptionsdialogbase.sip
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ reset the style to the original state
return the widget
%End

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


};


Expand Down
48 changes: 40 additions & 8 deletions src/gui/qgsoptionsdialogbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsoptionsdialogbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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


Expand Down

0 comments on commit 8074dc4

Please sign in to comment.