From 9633659744b7bb734f67cabd720e5fa5e3af0a78 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Fri, 12 May 2023 08:54:02 +0300 Subject: Fix QComboBox placeholder text visibility Due to a bug in Qt5.15.2, the placeholder text is not shown. Fixing it by implementing custom QComboBox and painting the placeholder text in paint event. This workaround can be removed once we start building IFW binaries with newer Qt version than 5.15.2 Change-Id: I203ad7ee47921f8d70ed1c550df2683bdfa80677 Reviewed-by: Arttu Tarkiainen --- src/libs/installer/componentselectionpage_p.cpp | 8 +++- src/libs/installer/componentselectionpage_p.h | 4 +- src/libs/installer/customcombobox.cpp | 54 +++++++++++++++++++++++++ src/libs/installer/customcombobox.h | 48 ++++++++++++++++++++++ src/libs/installer/installer.pro | 6 ++- 5 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 src/libs/installer/customcombobox.cpp create mode 100644 src/libs/installer/customcombobox.h (limited to 'src') diff --git a/src/libs/installer/componentselectionpage_p.cpp b/src/libs/installer/componentselectionpage_p.cpp index f60cf779a..048561f67 100644 --- a/src/libs/installer/componentselectionpage_p.cpp +++ b/src/libs/installer/componentselectionpage_p.cpp @@ -35,6 +35,7 @@ #include "component.h" #include "fileutils.h" #include "messageboxhandler.h" +#include "customcombobox.h" #include #include @@ -50,7 +51,6 @@ #include #include #include -#include #include #include @@ -136,9 +136,13 @@ ComponentSelectionPagePrivate::ComponentSelectionPagePrivate(ComponentSelectionP m_rightSideVLayout->addWidget(m_qbspPushButton, 0, Qt::AlignRight | Qt::AlignBottom); QHBoxLayout *topHLayout = new QHBoxLayout; - m_checkStateComboBox = new QComboBox(q); + + // Using custom combobox to workaround QTBUG-90595 + m_checkStateComboBox = new CustomComboBox(q); +#ifdef Q_OS_MACOS QStyledItemDelegate *delegate = new QStyledItemDelegate(this); m_checkStateComboBox->setItemDelegate(delegate); +#endif m_checkStateComboBox->setObjectName(QLatin1String("CheckStateComboBox")); topHLayout->addWidget(m_checkStateComboBox); diff --git a/src/libs/installer/componentselectionpage_p.h b/src/libs/installer/componentselectionpage_p.h index ed68fafa4..3667f000e 100644 --- a/src/libs/installer/componentselectionpage_p.h +++ b/src/libs/installer/componentselectionpage_p.h @@ -48,13 +48,13 @@ class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QStackedLayout; -class QComboBox; namespace QInstaller { class PackageManagerCore; class ComponentModel; class ComponentSelectionPage; +class CustomComboBox; class ComponentSelectionPagePrivate : public QObject { @@ -106,7 +106,7 @@ private: QLabel *m_sizeLabel; QLabel *m_descriptionLabel; QPushButton *m_qbspPushButton; - QComboBox *m_checkStateComboBox; + CustomComboBox *m_checkStateComboBox; QWidget *m_categoryWidget; QGroupBox *m_categoryGroupBox; QLabel *m_metadataProgressLabel; diff --git a/src/libs/installer/customcombobox.cpp b/src/libs/installer/customcombobox.cpp new file mode 100644 index 000000000..998364fe4 --- /dev/null +++ b/src/libs/installer/customcombobox.cpp @@ -0,0 +1,54 @@ +/************************************************************************** +** +** Copyright (C) 2023 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "customcombobox.h" + +#include + +using namespace QInstaller; + +CustomComboBox::CustomComboBox(QWidget *parent) + : QComboBox(parent) +{ +} + +void CustomComboBox::paintEvent(QPaintEvent *e) +{ + if (currentIndex() < 0 && !placeholderText().isEmpty()) { + QStylePainter painter(this); + painter.setPen(palette().color(QPalette::Text)); + QStyleOptionComboBox opt; + initStyleOption(&opt); + painter.drawComplexControl(QStyle::CC_ComboBox, opt); + opt.palette.setBrush(QPalette::ButtonText, opt.palette.placeholderText()); + opt.currentText = placeholderText(); + painter.drawControl(QStyle::CE_ComboBoxLabel, opt); + } else { + QComboBox::paintEvent(e); + } +} diff --git a/src/libs/installer/customcombobox.h b/src/libs/installer/customcombobox.h new file mode 100644 index 000000000..e022da5a8 --- /dev/null +++ b/src/libs/installer/customcombobox.h @@ -0,0 +1,48 @@ +/************************************************************************** +** +** Copyright (C) 2023 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#ifndef CUSTOMCOMBOBOX_H +#define CUSTOMCOMBOBOX_H + +#include + +namespace QInstaller { + +class CustomComboBox : public QComboBox +{ + Q_OBJECT +public: + CustomComboBox(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *e) override; +}; + +} // namespace QInstaller + +#endif // CUSTOMCOMBOBOX_H diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index 30d15c695..d25795d78 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -145,7 +145,8 @@ HEADERS += packagemanagercore.h \ abstractarchive.h \ directoryguard.h \ archivefactory.h \ - operationtracer.h + operationtracer.h \ + customcombobox.h SOURCES += packagemanagercore.cpp \ abstractarchive.cpp \ @@ -233,7 +234,8 @@ SOURCES += packagemanagercore.cpp \ packagesource.cpp \ repositorycategory.cpp \ componentselectionpage_p.cpp \ - commandlineparser.cpp + commandlineparser.cpp \ + customcombobox.cpp macos:SOURCES += fileutils_mac.mm -- cgit v1.2.3