From 991573f1fc0893a2ddb5bc59312414b20eaed304 Mon Sep 17 00:00:00 2001 From: Peter Lama Date: Sat, 16 Sep 2017 11:08:38 -0400 Subject: [PATCH] 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. --- src/Gui/FileDialog.cpp | 15 +++++++++++++-- src/Gui/FileDialog.h | 3 +++ src/Gui/Widgets.cpp | 14 +++++++++++++- src/Gui/Widgets.h | 3 +++ src/Gui/propertyeditor/PropertyItem.cpp | 4 ++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Gui/FileDialog.cpp b/src/Gui/FileDialog.cpp index c0f1347476..ef5ceeeb8c 100644 --- a/src/Gui/FileDialog.cpp +++ b/src/Gui/FileDialog.cpp @@ -36,6 +36,7 @@ # include # include # include +# include #endif #include @@ -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 * diff --git a/src/Gui/FileDialog.h b/src/Gui/FileDialog.h index 7db85fecad..fe7578fc39 100644 --- a/src/Gui/FileDialog.h +++ b/src/Gui/FileDialog.h @@ -183,6 +183,9 @@ private Q_SLOTS: void chooseFile(); void editingFinished(); +protected: + void resizeEvent(QResizeEvent*); + private: QLineEdit *lineEdit; QCompleter *completer; diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 60f3ff2fd7..6df9ec78d9 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -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; diff --git a/src/Gui/Widgets.h b/src/Gui/Widgets.h index bba360f3e4..5a4c803402 100644 --- a/src/Gui/Widgets.h +++ b/src/Gui/Widgets.h @@ -437,6 +437,9 @@ Q_SIGNALS: private Q_SLOTS: void changeText(); +protected: + void resizeEvent(QResizeEvent*); + private: InputType type; QString plainText; diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 22a6276094..7cc170b717 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -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()); }