Skip to content

Commit

Permalink
Fix infinitely growing widgets
Browse files Browse the repository at this point in the history
Fixes #16849
  • Loading branch information
nyalldawson committed Aug 2, 2017
1 parent a0010a1 commit 082dafe
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
1 change: 1 addition & 0 deletions python/gui/qgscolorbutton.sip
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class QgsColorButton : QToolButton
%End

virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;

QColor color() const;
%Docstring
Expand Down
1 change: 1 addition & 0 deletions python/gui/qgsfontbutton.sip
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class QgsFontButton : QToolButton
%End

virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;

QgsFontButton::Mode mode() const;
%Docstring
Expand Down
1 change: 1 addition & 0 deletions python/gui/qgssymbolbutton.sip
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class QgsSymbolButton : QToolButton
%End

virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;

void setSymbolType( QgsSymbol::SymbolType type );
%Docstring
Expand Down
25 changes: 16 additions & 9 deletions src/gui/qgscolorbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,26 @@ QgsColorButton::QgsColorButton( QWidget *parent, const QString &cdt, QgsColorSch
connect( mMenu, &QMenu::aboutToShow, this, &QgsColorButton::prepareMenu );
setMenu( mMenu );
setPopupMode( QToolButton::MenuButtonPopup );
}

QSize QgsColorButton::minimumSizeHint() const
{
//make sure height of button looks good under different platforms
QSize size;
#ifdef Q_OS_WIN
size = QSize( 120, 22 );
mMinimumSize = QSize( 120, 22 );
#else
size = QSize( 120, 28 );
mMinimumSize = QSize( 120, 28 );
#endif
int textHeight = fontMetrics().height() * 1.1;
return QSize( size.width(), qMax( size.height(), textHeight ) );

mMinimumSize.setHeight( qMax( static_cast<int>( fontMetrics().height() * 1.1 ), mMinimumSize.height() ) );
}



QSize QgsColorButton::minimumSizeHint() const
{
return mMinimumSize;
}

QSize QgsColorButton::sizeHint() const
{
return mMinimumSize;
}

const QPixmap &QgsColorButton::transparentBackground()
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgscolorbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class GUI_EXPORT QgsColorButton : public QToolButton
QgsColorButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &cdt = "", QgsColorSchemeRegistry *registry = nullptr );

virtual QSize minimumSizeHint() const override;
virtual QSize sizeHint() const override;

/** Return the currently selected color.
* \returns currently selected color
Expand Down Expand Up @@ -381,6 +382,7 @@ class GUI_EXPORT QgsColorButton : public QToolButton
Behavior mBehavior;
QString mColorDialogTitle;
QColor mColor;
QSize mMinimumSize;

QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;

Expand Down
15 changes: 11 additions & 4 deletions src/gui/qgsfontbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ QgsFontButton::QgsFontButton( QWidget *parent, const QString &dialogTitle )
connect( mMenu, &QMenu::aboutToShow, this, &QgsFontButton::prepareMenu );
setMenu( mMenu );
setPopupMode( QToolButton::MenuButtonPopup );
}

QSize QgsFontButton::minimumSizeHint() const
{
//make sure height of button looks good under different platforms
QSize size = QToolButton::minimumSizeHint();
int fontHeight = fontMetrics().height() * 1.4;
return QSize( size.width(), qMax( size.height(), fontHeight ) );
mSizeHint = QSize( size.width(), qMax( size.height(), fontHeight ) );
}

QSize QgsFontButton::minimumSizeHint() const
{
return mSizeHint;
}

QSize QgsFontButton::sizeHint() const
{
return mSizeHint;
}

void QgsFontButton::showSettingsDialog()
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsfontbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GUI_EXPORT QgsFontButton : public QToolButton
QgsFontButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );

virtual QSize minimumSizeHint() const override;
virtual QSize sizeHint() const override;

/**
* Returns the current button mode.
Expand Down Expand Up @@ -215,6 +216,8 @@ class GUI_EXPORT QgsFontButton : public QToolButton

private:

QSize mSizeHint;

Mode mMode = ModeTextRenderer;

QString mDialogTitle;
Expand Down
16 changes: 12 additions & 4 deletions src/gui/qgssymbolbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ QgsSymbolButton::QgsSymbolButton( QWidget *parent, const QString &dialogTitle )
connect( mMenu, &QMenu::aboutToShow, this, &QgsSymbolButton::prepareMenu );
setMenu( mMenu );
setPopupMode( QToolButton::MenuButtonPopup );
}

QSize QgsSymbolButton::minimumSizeHint() const
{
//make sure height of button looks good under different platforms
QSize size = QToolButton::minimumSizeHint();
int fontHeight = fontMetrics().height() * 1.4;
return QSize( size.width(), qMax( size.height(), fontHeight ) );
mSizeHint = QSize( size.width(), qMax( size.height(), fontHeight ) );
}

QSize QgsSymbolButton::minimumSizeHint() const
{

return mSizeHint;
}

QSize QgsSymbolButton::sizeHint() const
{
return mSizeHint;
}

void QgsSymbolButton::setSymbolType( QgsSymbol::SymbolType type )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgssymbolbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton
QgsSymbolButton( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &dialogTitle = QString() );

virtual QSize minimumSizeHint() const override;
virtual QSize sizeHint() const override;

/**
* Sets the symbol \a type which the button requires.
Expand Down Expand Up @@ -224,6 +225,8 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton

private:

QSize mSizeHint;

QString mDialogTitle;

QgsSymbol::SymbolType mType = QgsSymbol::Fill;
Expand Down

0 comments on commit 082dafe

Please sign in to comment.