Fix macOS button layout in property editor

The size of the "..." button calculated by QMacStyle was not correct,
causing other widgets in the layout to be clipped.

Also, set the size of all "..." buttons the same way.
This commit is contained in:
Peter Lama
2017-09-16 11:08:38 -04:00
committed by Yorik van Havre
parent 412376ca3f
commit 556d68680e
5 changed files with 36 additions and 3 deletions

View File

@@ -36,6 +36,7 @@
# include <QRadioButton>
# include <QStyle>
# include <QUrl>
# include <QResizeEvent>
#endif
#include <Base/Parameter.h>
@@ -589,7 +590,7 @@ FileChooser::FileChooser ( QWidget * parent )
{
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setMargin( 0 );
layout->setSpacing( 6 );
layout->setSpacing( 2 );
lineEdit = new QLineEdit ( this );
completer = new QCompleter ( this );
@@ -607,7 +608,11 @@ FileChooser::FileChooser ( QWidget * parent )
connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(editingFinished()));
button = new QPushButton(QLatin1String("..."), this);
button->setFixedWidth(2*button->fontMetrics().width(QLatin1String(" ... ")));
#if defined (Q_OS_MAC)
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
#endif
layout->addWidget(button);
connect( button, SIGNAL(clicked()), this, SLOT(chooseFile()));
@@ -619,6 +624,12 @@ FileChooser::~FileChooser()
{
}
void FileChooser::resizeEvent(QResizeEvent* e)
{
button->setFixedWidth(e->size().height());
button->setFixedHeight(e->size().height());
}
/**
* \property FileChooser::fileName
*

View File

@@ -183,6 +183,9 @@ private Q_SLOTS:
void chooseFile();
void editingFinished();
protected:
void resizeEvent(QResizeEvent*);
private:
QLineEdit *lineEdit;
QCompleter *completer;

View File

@@ -867,6 +867,9 @@ LabelButton::LabelButton (QWidget * parent)
layout->addWidget(label);
button = new QPushButton(QLatin1String("..."), this);
#if defined (Q_OS_MAC)
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
#endif
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(browse()));
@@ -880,6 +883,7 @@ LabelButton::~LabelButton()
void LabelButton::resizeEvent(QResizeEvent* e)
{
button->setFixedWidth(e->size().height());
button->setFixedHeight(e->size().height());
}
QLabel *LabelButton::getLabel() const
@@ -1298,7 +1302,9 @@ LabelEditor::LabelEditor (QWidget * parent)
this, SLOT(validateText(const QString &)));
button = new QPushButton(QLatin1String("..."), this);
button->setFixedWidth(2*button->fontMetrics().width(QLatin1String(" ... ")));
#if defined (Q_OS_MAC)
button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
#endif
layout->addWidget(button);
connect(button, SIGNAL(clicked()), this, SLOT(changeText()));
@@ -1310,6 +1316,12 @@ LabelEditor::~LabelEditor()
{
}
void LabelEditor::resizeEvent(QResizeEvent* e)
{
button->setFixedWidth(e->size().height());
button->setFixedHeight(e->size().height());
}
QString LabelEditor::text() const
{
return this->plainText;

View File

@@ -437,6 +437,9 @@ Q_SIGNALS:
private Q_SLOTS:
void changeText();
protected:
void resizeEvent(QResizeEvent*);
private:
InputType type;
QString plainText;

View File

@@ -3382,6 +3382,9 @@ LinkLabel::LinkLabel (QWidget * parent) : QWidget(parent)
layout->addWidget(label);
editButton = new QPushButton(QLatin1String("..."), this);
#if defined (Q_OS_MAC)
editButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // layout size from QMacStyle was not correct
#endif
editButton->setToolTip(tr("Change the linked object"));
layout->addWidget(editButton);
@@ -3440,6 +3443,7 @@ void LinkLabel::onEditClicked ()
void LinkLabel::resizeEvent(QResizeEvent* e)
{
editButton->setFixedWidth(e->size().height());
editButton->setFixedHeight(e->size().height());
}