Skip to content
Permalink
Browse files

Fix weird line edit styling error on Ubuntu

Ubuntu theme is incorrectly showing hidden actions in
line edits.

Fixes #18537

(cherry-picked from fb5caa7)
  • Loading branch information
nyalldawson committed Apr 2, 2018
1 parent 05eba14 commit 5672767e9ed971808dcc283280da131dcfe41517
Showing with 33 additions and 22 deletions.
  1. +27 −17 src/gui/qgsfilterlineedit.cpp
  2. +6 −5 src/gui/qgsfilterlineedit.h
@@ -32,20 +32,8 @@ QgsFilterLineEdit::QgsFilterLineEdit( QWidget *parent, const QString &nullValue
// icon size is about 2/3 height of text, but minimum size of 16
int iconSize = std::floor( std::max( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 0.75, 16.0 ) );

QIcon clearIcon;
clearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
clearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );
mClearAction = new QAction( clearIcon, QString(), this );
mClearAction->setCheckable( false );
addAction( mClearAction, QLineEdit::TrailingPosition );
connect( mClearAction, &QAction::triggered, this, &QgsFilterLineEdit::clearValue );
mClearAction->setVisible( false );

QIcon searchIcon = QgsApplication::getThemeIcon( "/search.svg" );
mSearchAction = new QAction( searchIcon, QString(), this );
mSearchAction->setCheckable( false );
addAction( mSearchAction, QLineEdit::LeadingPosition );
mSearchAction->setVisible( false );
mClearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearText.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Normal, QIcon::On );
mClearIcon.addPixmap( QgsApplication::getThemeIcon( "/mIconClearTextHover.svg" ).pixmap( QSize( iconSize, iconSize ) ), QIcon::Selected, QIcon::On );

connect( this, &QLineEdit::textChanged, this,
&QgsFilterLineEdit::onTextChanged );
@@ -59,13 +47,35 @@ void QgsFilterLineEdit::setShowClearButton( bool visible )

void QgsFilterLineEdit::setShowSearchIcon( bool visible )
{
mSearchIconVisible = visible;
mSearchAction->setVisible( visible );
if ( visible && !mSearchAction )
{
QIcon searchIcon = QgsApplication::getThemeIcon( "/search.svg" );
mSearchAction = new QAction( searchIcon, QString(), this );
mSearchAction->setCheckable( false );
addAction( mSearchAction, QLineEdit::LeadingPosition );
}
else if ( !visible && mSearchAction )
{
mSearchAction->deleteLater();
mSearchAction = nullptr;
}
}

void QgsFilterLineEdit::updateClearIcon()
{
mClearAction->setVisible( shouldShowClear() );
bool showClear = shouldShowClear();
if ( showClear && !mClearAction )
{
mClearAction = new QAction( mClearIcon, QString(), this );
mClearAction->setCheckable( false );
addAction( mClearAction, QLineEdit::TrailingPosition );
connect( mClearAction, &QAction::triggered, this, &QgsFilterLineEdit::clearValue );
}
else if ( !showClear && mClearAction )
{
mClearAction->deleteLater();
mClearAction = nullptr;
}
}

void QgsFilterLineEdit::focusInEvent( QFocusEvent *e )
@@ -19,6 +19,7 @@
#define QGSFILTERLINEEDIT_H

#include <QLineEdit>
#include <QIcon>
#include "qgis.h"
#include "qgis_gui.h"

@@ -64,7 +65,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
ClearToNull = 0, //!< Reset value to null
ClearToDefault, //!< Reset value to default value (see defaultValue() )
};
Q_ENUM( ClearMode );
Q_ENUM( ClearMode )

/**
* Constructor for QgsFilterLineEdit.
@@ -133,7 +134,7 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
* when no text is entered
* \since QGIS 3.0
*/
bool showSearchIcon() const { return mSearchIconVisible; }
bool showSearchIcon() const { return static_cast< bool >( mSearchAction ); }

/**
* Sets the default value for the widget. The default value is a value
@@ -271,12 +272,12 @@ class GUI_EXPORT QgsFilterLineEdit : public QLineEdit
void updateClearIcon();

private:
QAction *mClearAction;
QAction *mSearchAction;
QIcon mClearIcon;
QAction *mClearAction = nullptr;
QAction *mSearchAction = nullptr;
QAction *mBusySpinnerAction = nullptr;

bool mClearButtonVisible = true;
bool mSearchIconVisible = false;
bool mShowSpinner = false;

ClearMode mClearMode = ClearToNull;

0 comments on commit 5672767

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