Skip to content

Commit

Permalink
Improve appearance of QgsFileWidget
Browse files Browse the repository at this point in the history
Fix vertical alignment of widgets so that they are always
in line
  • Loading branch information
nyalldawson committed Aug 6, 2017
1 parent 6f7ef8a commit 10968ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/gui/qgsfilewidget.cpp
Expand Up @@ -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 );
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsfilewidget.h
Expand Up @@ -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;
Expand Down

0 comments on commit 10968ae

Please sign in to comment.