diff --git a/shop/favbutton.h b/shop/favbutton.h index f05b3a2..a44134e 100644 --- a/shop/favbutton.h +++ b/shop/favbutton.h @@ -2,6 +2,21 @@ #define FAVBUTTON_H #include +#include + +class FavButtonStyle : public QProxyStyle +{ +public: + FavButtonStyle(); + virtual ~FavButtonStyle(); + + // QStyle interface +public: + void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole) const; + +private: + Q_DISABLE_COPY(FavButtonStyle) +}; class FavButton : public QToolButton { @@ -17,6 +32,9 @@ signals: protected: virtual void dragEnterEvent(QDragEnterEvent *event) override; virtual void dropEvent(QDropEvent *event) override; + +private: + FavButtonStyle m_style; }; #endif // FAVBUTTON_H diff --git a/shop/settings/shopsettingsform.cpp b/shop/settings/shopsettingsform.cpp index b25fdf1..890aefc 100644 --- a/shop/settings/shopsettingsform.cpp +++ b/shop/settings/shopsettingsform.cpp @@ -67,6 +67,7 @@ void ShopSettingsForm::drawButtons() btn->setMinimumHeight(entity()->favBtnSize()); btn->setMinimumWidth(entity()->favBtnSize()); } + btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); ((QGridLayout*)ui->btnWidget->layout())->addWidget(btn, i, j); connect(btn, &FavButton::clicked, [this, btn](bool){ @@ -161,8 +162,33 @@ void ShopSettingsForm::on_favBtnSize_textChanged(const QString &arg1) drawButtons(); } +////////////////////////////////////////////////////////// +/// \brief FavButtonStyle::FavButtonStyle +/// + +FavButtonStyle::FavButtonStyle() + :QProxyStyle() +{ +} + +FavButtonStyle::~FavButtonStyle() +{ +} + +void FavButtonStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole) const +{ + flags |= Qt::TextWordWrap; + QProxyStyle::drawItemText(painter, rect, flags, pal, enabled, text, textRole); +} + +/////////////////////////////////////////////////////////// +/// \brief FavButton::FavButton +/// \param parent +/// + FavButton::FavButton(QWidget *parent) : QToolButton(parent) { + setStyle(&m_style); } void FavButton::dragEnterEvent(QDragEnterEvent *event) diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 4ed4416..944ba34 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -176,6 +176,7 @@ void ShopForm::loadButtons() btn->setMinimumHeight(settings->favBtnSize()); btn->setMinimumWidth(settings->favBtnSize()); } + btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); ((QGridLayout*)ui->favorites->layout())->addWidget(btn, i + 1, j); if (btnMap[btnName] != NULL)