21 #include <QToolButton>
23 #include <QFocusEvent>
27 , mNullValue( nullValue )
28 , mFocusInEvent( false )
30 btnClear =
new QToolButton(
this );
32 btnClear->setCursor( Qt::ArrowCursor );
33 btnClear->setFocusPolicy( Qt::NoFocus );
34 btnClear->setStyleSheet(
"QToolButton { border: none; padding: 0px; }" );
37 connect( btnClear, SIGNAL( clicked() ),
this, SLOT( clear() ) );
38 connect( btnClear, SIGNAL( clicked() ),
this, SIGNAL(
cleared() ) );
39 connect(
this, SIGNAL( textChanged(
const QString& ) ),
this,
40 SLOT( onTextChanged(
const QString& ) ) );
42 int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
43 mStyleSheet = QString(
"QLineEdit { padding-right: %1px; } " )
44 .arg( btnClear->sizeHint().width() + frameWidth + 1 );
46 QSize msz = minimumSizeHint();
47 setMinimumSize( qMax( msz.width(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ),
48 qMax( msz.height(), btnClear->sizeHint().height() + frameWidth * 2 + 2 ) );
56 mFocusInEvent =
false;
62 if ( e->reason() == Qt::MouseFocusReason &&
isNull() )
71 QSize sz = btnClear->sizeHint();
72 int frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
73 btnClear->move( rect().right() - frameWidth - sz.width(),
74 ( rect().bottom() + 1 - sz.height() ) / 2 );
77 void QgsFilterLineEdit::clear()
79 setText( mNullValue );
86 btnClear->setVisible( isEnabled() && !isReadOnly() && !
isNull() );
92 btnClear->setVisible( isEnabled() && !isReadOnly() && !
isNull() );
96 void QgsFilterLineEdit::onTextChanged(
const QString &text )
98 btnClear->setVisible( isEnabled() && !isReadOnly() && !
isNull() );
102 setStyleSheet( QString(
"QLineEdit { font: italic; color: gray; } %1" ).arg( mStyleSheet ) );
107 setStyleSheet( mStyleSheet );