Skip to content

Commit

Permalink
QToolBar: Fix QToolbar extension button icon after LayoutDirectionChange
Browse files Browse the repository at this point in the history
When the layout direction is changed after the QToolButton is created,
the extension button icon was not updated.

Task-number: QTBUG-66344
Change-Id: I8690b2c42c4f485a39490f16b15b8ee58e6f4ace
Reviewed-by: Friedemann Kleint <[email protected]>
  • Loading branch information
chehrlic committed Feb 15, 2018
1 parent ede6c44 commit 23eab78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/widgets/widgets/qtoolbarextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
****************************************************************************/

#include "qtoolbarextension_p.h"
#include <qpixmap.h>
#include <qevent.h>
#include <qstyle.h>
#include <qstylepainter.h>
#include <qstyleoption.h>
Expand All @@ -47,10 +47,11 @@ QT_BEGIN_NAMESPACE

QToolBarExtension::QToolBarExtension(QWidget *parent)
: QToolButton(parent)
, m_orientation(Qt::Horizontal)
{
setObjectName(QLatin1String("qt_toolbar_ext_button"));
setAutoRaise(true);
setOrientation(Qt::Horizontal);
setOrientation(m_orientation);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setCheckable(true);
}
Expand All @@ -63,7 +64,8 @@ void QToolBarExtension::setOrientation(Qt::Orientation o)
setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, &opt));
} else {
setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton, &opt));
}
}
m_orientation = o;
}

void QToolBarExtension::paintEvent(QPaintEvent *)
Expand All @@ -83,6 +85,18 @@ QSize QToolBarExtension::sizeHint() const
return QSize(ext, ext);
}

bool QToolBarExtension::event(QEvent *event)
{
switch (event->type()) {
case QEvent::LayoutDirectionChange:
setOrientation(m_orientation);
break;
default:
break;
}
return QToolButton::event(event);
}

QT_END_NAMESPACE

#include "moc_qtoolbarextension_p.cpp"
6 changes: 6 additions & 0 deletions src/widgets/widgets/qtoolbarextension_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class Q_AUTOTEST_EXPORT QToolBarExtension : public QToolButton

public Q_SLOTS:
void setOrientation(Qt::Orientation o);

protected:
bool event(QEvent *e) override;

private:
Qt::Orientation m_orientation;
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 23eab78

Please sign in to comment.