QToolBar: Fix QToolbar extension button icon after LayoutDirectionChange

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 <Friedemann.Kleint@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-02-12 22:44:32 +01:00
parent ede6c44756
commit 23eab78f51
2 changed files with 23 additions and 3 deletions

View File

@ -38,7 +38,7 @@
****************************************************************************/
#include "qtoolbarextension_p.h"
#include <qpixmap.h>
#include <qevent.h>
#include <qstyle.h>
#include <qstylepainter.h>
#include <qstyleoption.h>
@ -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);
}
@ -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 *)
@ -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"

View File

@ -69,6 +69,12 @@ public:
public Q_SLOTS:
void setOrientation(Qt::Orientation o);
protected:
bool event(QEvent *e) override;
private:
Qt::Orientation m_orientation;
};
QT_END_NAMESPACE