summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-04-13 20:01:52 +0200
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2020-04-13 22:44:52 +0200
commit0230c87d481ae887555404772d9bb6c41c5aab92 (patch)
tree5ff2e52d897cf68b80e1fa695cc22e0be326fbf0
parent522e868ef42ec8d08bbc193386e698900d995dd7 (diff)
widget/wcolorpicker: Resize WColorPicker(Action) after palette change
-rw-r--r--src/widget/wcolorpicker.cpp5
-rw-r--r--src/widget/wcolorpickeraction.cpp7
-rw-r--r--src/widget/wcolorpickeraction.h9
3 files changed, 21 insertions, 0 deletions
diff --git a/src/widget/wcolorpicker.cpp b/src/widget/wcolorpicker.cpp
index 75f127dbd2..722d08e091 100644
--- a/src/widget/wcolorpicker.cpp
+++ b/src/widget/wcolorpicker.cpp
@@ -46,6 +46,9 @@ WColorPicker::WColorPicker(Options options, const ColorPalette& palette, QWidget
pLayout->setMargin(0);
pLayout->setContentsMargins(0, 0, 0, 0);
+ pLayout->setSizeConstraint(QLayout::SetFixedSize);
+ setSizePolicy(QSizePolicy());
+
// Unfortunately, not all styles supported by Qt support setting a
// background color for QPushButtons (see
// https://bugreports.qt.io/browse/QTBUG-11089). For example, when using
@@ -130,6 +133,8 @@ void WColorPicker::addColorButtons() {
addCustomColorButton(pLayout, row, column);
column++;
}
+
+ adjustSize();
}
void WColorPicker::addColorButton(mixxx::RgbColor color, QGridLayout* pLayout, int row, int column) {
diff --git a/src/widget/wcolorpickeraction.cpp b/src/widget/wcolorpickeraction.cpp
index c1d34d916c..085f1fe001 100644
--- a/src/widget/wcolorpickeraction.cpp
+++ b/src/widget/wcolorpickeraction.cpp
@@ -7,9 +7,11 @@ WColorPickerAction::WColorPickerAction(WColorPicker::Options options, const Colo
QHBoxLayout* pLayout = new QHBoxLayout();
pLayout->addWidget(m_pColorPicker);
+ pLayout->setSizeConstraint(QLayout::SetFixedSize);
QWidget* pWidget = new QWidget();
pWidget->setLayout(pLayout);
+ pWidget->setSizePolicy(QSizePolicy());
setDefaultWidget(pWidget);
}
@@ -23,4 +25,9 @@ void WColorPickerAction::setSelectedColor(mixxx::RgbColor::optional_t color) {
void WColorPickerAction::setColorPalette(const ColorPalette& palette) {
m_pColorPicker->setColorPalette(palette);
+ QWidget* pWidget = defaultWidget();
+ VERIFY_OR_DEBUG_ASSERT(pWidget) {
+ return;
+ }
+ pWidget->adjustSize();
}
diff --git a/src/widget/wcolorpickeraction.h b/src/widget/wcolorpickeraction.h
index ca173d5a7d..2956634378 100644
--- a/src/widget/wcolorpickeraction.h
+++ b/src/widget/wcolorpickeraction.h
@@ -17,6 +17,15 @@ class WColorPickerAction : public QWidgetAction {
void resetSelectedColor();
void setSelectedColor(mixxx::RgbColor::optional_t color);
+
+ /// Set a new color palette for the underlying color picker.
+ ///
+ /// After calling this, your need to tell Qt that the menu size needs to be
+ /// recalculated, e.g.:
+ ///
+ /// m_pColorPickerAction->setColorPalette(palette);
+ /// QResizeEvent resizeEvent(QSize(), m_pMenu->size());
+ /// qApp->sendEvent(m_pMenu, &resizeEvent);
void setColorPalette(const ColorPalette& palette);
signals: