Skip to content
Permalink
Browse files

Fix infinitely growing widgets

Fixes #16849
  • Loading branch information
nyalldawson committed Aug 2, 2017
1 parent a0010a1 commit 082dafe22d5dd98ddb5abb2c18a96c29dbe56355
@@ -45,6 +45,7 @@ class QgsColorButton : QToolButton
%End

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

QColor color() const;
%Docstring
@@ -46,6 +46,7 @@ class QgsFontButton : QToolButton
%End

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

QgsFontButton::Mode mode() const;
%Docstring
@@ -31,6 +31,7 @@ class QgsSymbolButton : QToolButton
%End

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

void setSymbolType( QgsSymbol::SymbolType type );
%Docstring
@@ -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()
@@ -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
@@ -381,6 +382,7 @@ class GUI_EXPORT QgsColorButton : public QToolButton
Behavior mBehavior;
QString mColorDialogTitle;
QColor mColor;
QSize mMinimumSize;

QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;

@@ -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()
@@ -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.
@@ -215,6 +216,8 @@ class GUI_EXPORT QgsFontButton : public QToolButton

private:

QSize mSizeHint;

Mode mMode = ModeTextRenderer;

QString mDialogTitle;
@@ -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 )
@@ -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.
@@ -224,6 +225,8 @@ class GUI_EXPORT QgsSymbolButton : public QToolButton

private:

QSize mSizeHint;

QString mDialogTitle;

QgsSymbol::SymbolType mType = QgsSymbol::Fill;

0 comments on commit 082dafe

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