void QgsDateTimeEdit::resizeEvent( QResizeEvent *event ) { QDateTimeEdit::resizeEvent( event ); QSize sz = mClearButton->sizeHint(); mClearButton->move( rect().right() - frameWidth() - spinButtonWidth() - sz.width(), ( rect().bottom() + 1 - sz.height() ) / 2 ); mNullLabel->move( 0, 0 ); mNullLabel->setMinimumSize( rect().adjusted( 0, 0, -spinButtonWidth(), 0 ).size() ); mNullLabel->setMaximumSize( rect().adjusted( 0, 0, -spinButtonWidth(), 0 ).size() ); }
void QgsDateTimeEdit::mousePressEvent( QMouseEvent *event ) { QRect lerect = rect().adjusted( 0, 0, -spinButtonWidth(), 0 ); if ( mAllowNull && mIsNull && lerect.contains( event->pos() ) ) return; QDateTimeEdit::mousePressEvent( event ); }
QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent ) : QDateTimeEdit( parent ) { mClearButton = new QToolButton( this ); mClearButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconClearText.svg" ) ) ); mClearButton->setCursor( Qt::ArrowCursor ); mClearButton->setStyleSheet( QStringLiteral( "position: absolute; border: none; padding: 0px;" ) ); mClearButton->hide(); connect( mClearButton, &QAbstractButton::clicked, this, &QgsDateTimeEdit::clear ); mNullLabel = new QLineEdit( QgsApplication::nullRepresentation(), this ); mNullLabel->setReadOnly( true ); mNullLabel->setStyleSheet( QStringLiteral( "position: absolute; border: none; font-style: italic; color: grey;" ) ); mNullLabel->hide(); setStyleSheet( QStringLiteral( ".QWidget, QLineEdit, QToolButton { padding-right: %1px; }" ).arg( mClearButton->sizeHint().width() + spinButtonWidth() + frameWidth() + 1 ) ); QSize msz = minimumSizeHint(); setMinimumSize( std::max( msz.width(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ), std::max( msz.height(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ) ); connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed ); // init with current time so mIsNull is properly initialized QDateTimeEdit::setDateTime( QDateTime::currentDateTime() ); setMinimumEditDateTime(); }
QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent ) : QDateTimeEdit( parent ) , mAllowNull( true ) , mIsNull( true ) { mClearButton = new QToolButton( this ); mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) ); mClearButton->setCursor( Qt::ArrowCursor ); mClearButton->setStyleSheet( "position: absolute; border: none; padding: 0px;" ); mClearButton->hide(); connect( mClearButton, SIGNAL( clicked() ), this, SLOT( clear() ) ); mNullLabel = new QLineEdit( QSettings().value( "qgis/nullValue", "NULL" ).toString(), this ); mNullLabel->setReadOnly( true ); mNullLabel->setStyleSheet( "position: absolute; border: none; font-style: italic; color: grey;" ); mNullLabel->hide(); setStyleSheet( QString( "padding-right: %1px;" ).arg( mClearButton->sizeHint().width() + spinButtonWidth() + frameWidth() + 1 ) ); QSize msz = minimumSizeHint(); setMinimumSize( qMax( msz.width(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ), qMax( msz.height(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ) ); connect( this, SIGNAL( dateTimeChanged( QDateTime ) ), this, SLOT( changed( QDateTime ) ) ); // init with current time so mIsNull is properly initialized QDateTimeEdit::setDateTime( QDateTime::currentDateTime() ); }