diff options
| author | Ivan Solovev <ivan.solovev@qt.io> | 2025-06-10 16:31:16 +0200 |
|---|---|---|
| committer | Ivan Solovev <ivan.solovev@qt.io> | 2025-06-13 12:15:41 +0200 |
| commit | 7322e051c9c3d8dc715c20a3d42d9be83ea2295c (patch) | |
| tree | 4b13c016a33e3793ef51e3e77d1db940596a5249 /src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp | |
| parent | 2d4bebdb51bbf720fe719f5e6ea54b04bde36510 (diff) | |
QQuickDialogs: fix dark mode in SideBar
The patch explicitly sets the colors from the palette for some of the
elements of the SideBar.
It also removes the usage of Basic.darkShade color, which is not
available in general case, replacing it with the palette.dark color.
A more complicated problem was related to the icons in buttonDelegate
and addFavoriteDelegate, that were not updating their colors.
The reason for that was that the unrelying C++ code was constructing
the delegates using QQmlComponent::createWithInitialProperties(), and
passed a QQuickIcon object as one of the properties. As a result, the
original binding on icon.color was removed.
To keep the binding, construct the components with a default icon,
then manually set the source and the size. This approach is slower,
but it allows to preserve the original binding from the QtQuick Button
component.
Last affected element was the drag pixmap, which was always using
the original color. Use the buttonText() palette color to update
all the non-transparent pixels of the icon before using it in the
drag.
Fixes: QTBUG-122738
Pick-to: 6.10 6.9
Change-Id: Ibf4182b1c5a631fe7043e8d76ed98629c69ab4d6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp')
| -rw-r--r-- | src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp index 88f1370135..b034cdd7e8 100644 --- a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp +++ b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogdelegate.cpp @@ -204,7 +204,34 @@ void QQuickFileDialogTapHandler::grabFolder() if (m_drag.isNull()) return; - QPixmap pixmap(":/qt-project.org/imports/QtQuick/Dialogs/quickimpl/images/sidebar-folder.png"_L1); + QQuickPalette *palette = [this]() -> QQuickPalette* { + auto *delegate = qobject_cast<QQuickFileDialogDelegate*>(parent()); + if (delegate) { + QQuickDialog *dlg = delegate->dialog(); + if (dlg) { + QQuickDialogPrivate *priv = QQuickDialogPrivate::get(dlg); + if (priv) + return priv->palette(); + } + } + return nullptr; + }(); + + // TODO: use proper @Nx scaling + const auto src = ":/qt-project.org/imports/QtQuick/Dialogs/quickimpl/images/sidebar-folder.png"_L1; + QImage img = QImage(src).convertToFormat(QImage::Format_ARGB32); + + if (!img.isNull() && palette) { + const QColor iconColor = palette->buttonText(); + if (iconColor.alpha() > 0) { + // similar to what QQuickIconImage does + QPainter painter(&img); + painter.setCompositionMode(QPainter::CompositionMode_SourceIn); + painter.fillRect(img.rect(), iconColor); + } + } + + QPixmap pixmap = QPixmap::fromImage(std::move(img)); auto *mimeData = new QMimeData(); mimeData->setImageData(pixmap); m_drag->setMimeData(mimeData); |
