Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] add lineedit with builtin clear button
- Loading branch information
Showing
7 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
/** LineEdit with builtin clear button | ||
*/ | ||
class QgsFilterLineEdit : QLineEdit | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsfilterlineedit.h> | ||
%End | ||
|
||
public: | ||
QgsFilterLineEdit( QWidget* parent = 0 ); | ||
|
||
protected: | ||
void resizeEvent( QResizeEvent * ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*************************************************************************** | ||
qgsfilterlineedit.cpp | ||
------------------------ | ||
begin : October 27, 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsfilterlineedit.h" | ||
#include "qgsapplication.h" | ||
|
||
#include <QToolButton> | ||
#include <QStyle> | ||
|
||
QgsFilterLineEdit::QgsFilterLineEdit( QWidget* parent ) : QLineEdit( parent ) | ||
{ | ||
btnClear = new QToolButton( this ); | ||
btnClear->setIcon( QgsApplication::getThemeIcon( "/mIconClear.png" ) ); | ||
btnClear->setCursor(Qt::ArrowCursor); | ||
btnClear->setStyleSheet( "QToolButton { border: none; padding: 0px; }" ); | ||
btnClear->hide(); | ||
|
||
connect( btnClear, SIGNAL( clicked() ), this, SLOT( clear() ) ); | ||
connect( this, SIGNAL( textChanged( const QString& ) ), this, | ||
SLOT( toggleClearButton( const QString& ) ) ); | ||
|
||
int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); | ||
setStyleSheet( QString( "QLineEdit { padding-right: %1px; } " ) | ||
.arg( btnClear->sizeHint().width() + frameWidth + 1 ) ); | ||
|
||
QSize msz = minimumSizeHint(); | ||
setMinimumSize( qMax( msz.width(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ), | ||
qMax( msz.height(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ) ); | ||
} | ||
|
||
void QgsFilterLineEdit::resizeEvent( QResizeEvent * ) | ||
{ | ||
QSize sz = btnClear->sizeHint(); | ||
int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); | ||
btnClear->move( rect().right() - frameWidth - sz.width(), | ||
( rect().bottom() + 1 - sz.height() ) / 2 ); | ||
} | ||
|
||
void QgsFilterLineEdit::toggleClearButton( const QString &text ) | ||
{ | ||
btnClear->setVisible( !text.isEmpty() ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*************************************************************************** | ||
qgsfilterlineedit.h | ||
------------------------ | ||
begin : October 27, 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSFILTERLINEEDIT_H | ||
#define QGSFILTERLINEEDIT_H | ||
|
||
#include <QLineEdit> | ||
|
||
class QToolButton; | ||
|
||
/** \ingroup gui | ||
* Lineedit with builtin clear button | ||
**/ | ||
class GUI_EXPORT QgsFilterLineEdit : public QLineEdit | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsFilterLineEdit( QWidget* parent = 0 ); | ||
|
||
protected: | ||
void resizeEvent( QResizeEvent * ); | ||
|
||
private slots: | ||
void toggleClearButton( const QString &text ); | ||
|
||
private: | ||
QToolButton *btnClear; | ||
}; | ||
|
||
#endif // QGSFILTERLINEEDIT_H |