void LineEdit::init() { m_clearButton = new QToolButton(this); const QPixmap pixmap(QLatin1String(":/icons/edit-clear-locationbar-rtl.png")); m_clearButton->setIcon(QIcon(pixmap)); m_clearButton->setIconSize(pixmap.size()); m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setToolTip(tr("Clear input field")); m_clearButton->setFocusPolicy(Qt::NoFocus); m_clearButton->hide(); connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButton(QString))); const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); m_clearButton->setStyleSheet(QString::fromUtf8("QToolButton { border: none; padding-left: 1px; padding-top: %1px; padding-bottom: %1px; padding-right: %1px; }") .arg(frameWidth + 1)); setStyleSheet(QString::fromUtf8("QLineEdit { padding-right: %1px; }") .arg(m_clearButton->sizeHint().width())); QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->addStretch(); layout->addWidget(m_clearButton); connect(this, SIGNAL(editingFinished()), this, SLOT(doEmitTextEditingFinished())); }
MarbleLineEdit::MarbleLineEdit( QWidget *parent ) : QLineEdit( parent ), d( new MarbleLineEditPrivate( this ) ) { updateClearButtonIcon( text() ); updateClearButton(); setDecorator( d->m_decoratorPixmap ); connect( this, SIGNAL(textChanged(QString)), SLOT(updateClearButtonIcon(QString)) ); connect( &d->m_progressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()) ); }
RoutingLineEdit::RoutingLineEdit( QWidget *parent ) : QLineEdit( parent ), d( new RoutingLineEditPrivate( this ) ) { updateClearButtonIcon( text() ); updateClearButton(); // Padding for clear button to avoid text underflow QString const direction = layoutDirection() == Qt::LeftToRight ? "right" : "left"; if ( !MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen ) { setStyleSheet( QString( ":enabled { padding-%1: %2; }").arg( direction).arg( 18 ) ); } connect( this, SIGNAL( textChanged( QString ) ), SLOT( updateClearButtonIcon( QString ) ) ); }
void LineEdit::init() { m_clearButton = new QToolButton(this); const QPixmap pixmap(":/icons/edit-clear-locationbar-rtl.png"); m_clearButton->setIcon(QIcon(pixmap)); m_clearButton->setIconSize(pixmap.size()); m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); m_clearButton->setToolTip(tr("Clear input field")); m_clearButton->hide(); connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButton(QString))); // const int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); // setStyleSheet(QString("QLineEdit { padding-right: %1px; width: %2px; height: %3px; }") // .arg(m_clearButton->sizeHint().width() + frameWidth + 1) // .arg(sizeHint().width()) // .arg(sizeHint().height())); setStyleSheet(QString("QLineEdit { padding-right: %1px; }") .arg(m_clearButton->sizeHint().width() + style()->pixelMetric(QStyle::PM_DefaultFrameWidth) + 1)); }
void QExLineEdit::setClearButtonShown(bool show) { if (show) { if (d->clearButton) return; d->clearButton = new QExLineEditButton(this); d->clearButton->setCursor(Qt::ArrowCursor); // d->clearButton->setToolTip("Clear text"); updateClearButtonIcon(text()); updateClearButton(); // connect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButtonIcon(QString))); } else { // disconnect(this, SIGNAL(textChanged(QString)), this, SLOT(updateClearButtonIcon(QString))); delete d->clearButton; d->clearButton = 0; d->clickInClear = false; } }
void MarbleLineEdit::resizeEvent( QResizeEvent * event ) { updateClearButton(); QLineEdit::resizeEvent( event ); }
void RoutingLineEdit::resizeEvent( QResizeEvent * event ) { updateClearButton(); QLineEdit::resizeEvent( event ); }