Skip to content
Permalink
Browse files

Improve appearance of QgsFileWidget

Fix vertical alignment of widgets so that they are always
in line
  • Loading branch information
nyalldawson committed Aug 5, 2017
1 parent 6f7ef8a commit 10968aeb2501282afc953c6877b4646c935ae323
Showing with 16 additions and 6 deletions.
  1. +15 −6 src/gui/qgsfilewidget.cpp
  2. +1 −0 src/gui/qgsfilewidget.h
@@ -44,8 +44,8 @@ QgsFileWidget::QgsFileWidget( QWidget *parent )
setBackgroundRole( QPalette::Window );
setAutoFillBackground( true );

QGridLayout *layout = new QGridLayout();
layout->setMargin( 0 );
mLayout = new QHBoxLayout();
mLayout->setMargin( 0 );

// If displaying a hyperlink, use a QLabel
mLinkLabel = new QLabel( this );
@@ -56,20 +56,19 @@ QgsFileWidget::QgsFileWidget( QWidget *parent )
mLinkLabel->setEnabled( true );
mLinkLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
mLinkLabel->setTextFormat( Qt::RichText );
layout->addWidget( mLinkLabel, 0, 0 );
mLinkLabel->hide(); // do not show by default

// otherwise, use the traditional QLineEdit
mLineEdit = new QgsFilterLineEdit( this );
connect( mLineEdit, &QLineEdit::textChanged, this, &QgsFileWidget::textEdited );
layout->addWidget( mLineEdit, 1, 0 );
mLayout->addWidget( mLineEdit );

mFileWidgetButton = new QToolButton( this );
mFileWidgetButton->setText( QStringLiteral( "" ) );
connect( mFileWidgetButton, &QAbstractButton::clicked, this, &QgsFileWidget::openFileDialog );
layout->addWidget( mFileWidgetButton, 0, 1, 2, 1 );
mLayout->addWidget( mFileWidgetButton );

setLayout( layout );
setLayout( mLayout );
}

QString QgsFileWidget::filePath()
@@ -142,6 +141,16 @@ void QgsFileWidget::setUseLink( bool useLink )
mUseLink = useLink;
mLinkLabel->setVisible( mUseLink );
mLineEdit->setVisible( !mUseLink );
if ( mUseLink )
{
mLayout->removeWidget( mLineEdit );
mLayout->insertWidget( 0, mLinkLabel );
}
else
{
mLayout->removeWidget( mLinkLabel );
mLayout->insertWidget( 0, mLineEdit );
}
}

bool QgsFileWidget::fullUrl() const
@@ -159,6 +159,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
QLabel *mLinkLabel = nullptr;
QgsFilterLineEdit *mLineEdit = nullptr;
QToolButton *mFileWidgetButton = nullptr;
QHBoxLayout *mLayout = nullptr;

//! returns a HTML code with a link to the given file path
QString toUrl( const QString &path ) const;

0 comments on commit 10968ae

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