https://bugs.kde.org/show_bug.cgi?id=525238
--- Comment #6 from [email protected] --- Following up on your question about the combobox and the slider. Here is an approach that works with the flattened toolbar from 626cd7fb. I tested it on master (f1f75253) on both wayland and xcb. - The session combobox shrinks to one toolbar button wide while the bar is vertical: AdjustToMinimumContentsLengthWithIcon, capped at the sizeHint width of a real tool button. Its dropdown list keeps a minimum width, so the session names stay readable. Both revert when the bar goes back to the top or bottom. - FactorWidget creates the slider in the toolbar's current orientation and follows QToolBar::orientationChanged. It limits only the length along the toolbar axis (100px), so a vertical bar gets a short vertical slider. Both react to QToolBar::orientationChanged, which buildToolBar() emits from setOrientation() before it reads sizeHint(), so the bar is sized for the new contents. Result: docked left or right, the bar is 46px wide instead of 226px. Docked at the top, it is the same as before (735px). On wayland the dropdown opens at full width on both sides; on the right edge it opens towards the centre. I couldn't check the dropdown on xcb, because my automated setup doesn't capture the combo popup there, even on unmodified master. diff --git a/factorwidget.cpp b/factorwidget.cpp index 1cb410d6..8d810b96 100644 --- a/factorwidget.cpp +++ b/factorwidget.cpp @@ -43,9 +43,21 @@ QWidget *FactorWidget::createWidget(QWidget *parent) return QWidgetAction::createWidget(parent); } - QSlider *s = new QSlider(Qt::Horizontal, _parent); + QSlider *s = new QSlider(_parent->orientation(), _parent); s->setRange(100, 200); - s->setMaximumWidth(100); + + // Follow the toolbar's orientation and only limit the slider along that axis, so a + // toolbar docked left/right gets a short vertical slider instead of a wide one. + auto applyOrientation = [s](Qt::Orientation orientation) { + s->setOrientation(orientation); + if (orientation == Qt::Vertical) { + s->setMaximumSize(QWIDGETSIZE_MAX, 100); + } else { + s->setMaximumSize(100, QWIDGETSIZE_MAX); + } + }; + applyOrientation(_parent->orientation()); + connect(_parent, &QToolBar::orientationChanged, s, applyOrientation); connect(s, &QSlider::valueChanged, m_receiver, &MainWindow::setFactor); connect(m_receiver, &MainWindow::factorUpdated, s, &QSlider::setValue); diff --git a/mainwindow.cpp b/mainwindow.cpp index c704c57f..51891957 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -31,6 +31,7 @@ #include <KToggleFullScreenAction> #include <KToolBar> +#include <QAbstractItemView> #include <QClipboard> #include <QDockWidget> #include <QFontMetrics> @@ -980,6 +981,18 @@ void MainWindow::showRemoteViewToolbar() stickToolBarAction->setText(i18n("Stick Toolbar")); connect(stickToolBarAction, SIGNAL(triggered(bool)), m_toolBar, SLOT(setSticky(bool))); m_toolBar->addAction(stickToolBarAction); + + // When docked left/right, shrink the session combobox to one toolbar button wide so + // the bar stays a slim column. + connect(m_toolBar, &QToolBar::orientationChanged, sessionComboBox, [this, sessionComboBox](Qt::Orientation orientation) { + const bool vertical = orientation == Qt::Vertical; + const QWidget *button = m_toolBar->widgetForAction(actionCollection()->action(QStringLiteral("switch_fullscreen"))); + sessionComboBox->setSizeAdjustPolicy(vertical ? QComboBox::AdjustToMinimumContentsLengthWithIcon : QComboBox::AdjustToContents); + sessionComboBox->setMaximumWidth(vertical && button ? button->sizeHint().width() : QWIDGETSIZE_MAX); + // the dropdown list is only as wide as the combobox by default; keep the names readable + QAbstractItemView *list = sessionComboBox->view(); + list->setMinimumWidth(vertical ? list->sizeHintForColumn(0) + 2 * list->frameWidth() : 0); + }); } } -- You are receiving this mail because: You are watching all bug changes.
