mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 22:49:00 +01:00
Merge pull request #7845 from jordan-woyak/elided-button-fix
DolphinQt: Fix ElidedButton (MappingButton) from growing with long text.
This commit is contained in:
commit
66a8220011
@ -32,7 +32,6 @@
|
|||||||
#include "InputCommon/ControllerInterface/Device.h"
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
|
|
||||||
constexpr int SLIDER_TICK_COUNT = 100;
|
constexpr int SLIDER_TICK_COUNT = 100;
|
||||||
constexpr int VERTICAL_PADDING = 2;
|
|
||||||
|
|
||||||
static QString EscapeAmpersand(QString&& string)
|
static QString EscapeAmpersand(QString&& string)
|
||||||
{
|
{
|
||||||
@ -48,18 +47,13 @@ MappingButton::MappingButton(MappingWidget* widget, ControlReference* ref, bool
|
|||||||
: ElidedButton(EscapeAmpersand(QString::fromStdString(ref->GetExpression()))), m_parent(widget),
|
: ElidedButton(EscapeAmpersand(QString::fromStdString(ref->GetExpression()))), m_parent(widget),
|
||||||
m_reference(ref)
|
m_reference(ref)
|
||||||
{
|
{
|
||||||
// Force all mapping buttons to use stay at a minimal height
|
// Force all mapping buttons to stay at a minimal height.
|
||||||
int height = QFontMetrics(qApp->font()).height() + 2 * VERTICAL_PADDING;
|
setFixedHeight(minimumSizeHint().height());
|
||||||
|
|
||||||
setMinimumHeight(height);
|
// Make sure that long entries don't throw our layout out of whack.
|
||||||
|
setFixedWidth(112);
|
||||||
|
|
||||||
// macOS needs some wiggle room to always get round buttons
|
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||||
setMaximumHeight(height + 8);
|
|
||||||
|
|
||||||
// Make sure that long entries don't throw our layout out of whack
|
|
||||||
setMaximumWidth(115);
|
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
||||||
|
|
||||||
Connect();
|
Connect();
|
||||||
setToolTip(
|
setToolTip(
|
||||||
|
@ -27,6 +27,14 @@ void ElidedButton::setElideMode(Qt::TextElideMode elide_mode)
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSize ElidedButton::sizeHint() const
|
||||||
|
{
|
||||||
|
// Long text produces big sizeHints which is throwing layouts off
|
||||||
|
// even when setting fixed sizes. This seems like a Qt layout bug.
|
||||||
|
// Let's always return the sizeHint of an empty button to work around this.
|
||||||
|
return QPushButton(parentWidget()).sizeHint();
|
||||||
|
}
|
||||||
|
|
||||||
void ElidedButton::paintEvent(QPaintEvent* event)
|
void ElidedButton::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
QStyleOptionButton option;
|
QStyleOptionButton option;
|
||||||
|
@ -12,10 +12,13 @@ class ElidedButton : public QPushButton
|
|||||||
public:
|
public:
|
||||||
explicit ElidedButton(const QString& text = QStringLiteral(""),
|
explicit ElidedButton(const QString& text = QStringLiteral(""),
|
||||||
Qt::TextElideMode elide_mode = Qt::ElideRight);
|
Qt::TextElideMode elide_mode = Qt::ElideRight);
|
||||||
|
|
||||||
Qt::TextElideMode elideMode() const;
|
Qt::TextElideMode elideMode() const;
|
||||||
void setElideMode(Qt::TextElideMode elide_mode);
|
void setElideMode(Qt::TextElideMode elide_mode);
|
||||||
|
|
||||||
|
QSize sizeHint() const final override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) final override;
|
||||||
Qt::TextElideMode m_elide_mode;
|
Qt::TextElideMode m_elide_mode;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user