diff --git a/app/ToolTips/tooltipmanager.cpp b/app/ToolTips/tooltipmanager.cpp index 7abc70ec..703a430c 100644 --- a/app/ToolTips/tooltipmanager.cpp +++ b/app/ToolTips/tooltipmanager.cpp @@ -1,232 +1,232 @@ /******************************************************************************* * Copyright (C) 2008 by Konstantin Heil * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *******************************************************************************/ #include "tooltipmanager.h" #include "MenuItem.h" #include #include #include #include #include #include #include #include #include #include #include class IconLoaderSingleton { public: IconLoaderSingleton() = default; KIconLoader self; }; -Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf); +Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf) class ToolTipManager::Private { public: Private() : tooltip(nullptr), view(nullptr), timer(nullptr), delay(300) { } KToolTipWidget *tooltip; QAbstractItemView* view; QTimer* timer; QModelIndex item; QRect itemRect; int delay; }; ToolTipManager::ToolTipManager(QAbstractItemView* parent) : QObject(parent) , d(new ToolTipManager::Private) { d->view = parent; d->tooltip = new KToolTipWidget(d->view); d->tooltip->setHideDelay(0); connect(parent, &QAbstractItemView::viewportEntered, this, &ToolTipManager::hideToolTip); connect(parent, &QAbstractItemView::entered, this, &ToolTipManager::requestToolTip); d->timer = new QTimer(this); d->timer->setSingleShot(true); connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); // When the mousewheel is used, the items don't get a hovered indication // (Qt-issue #200665). To assure that the tooltip still gets hidden, // the scrollbars are observed. connect(parent->horizontalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip); connect(parent->verticalScrollBar(), &QAbstractSlider::valueChanged, this, &ToolTipManager::hideToolTip); d->view->viewport()->installEventFilter(this); } ToolTipManager::~ToolTipManager() { delete d; } bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { if (watched == d->view->viewport()) { switch (event->type()) { case QEvent::Leave: case QEvent::MouseButtonPress: hideToolTip(); break; default: break; } } return QObject::eventFilter(watched, event); } void ToolTipManager::requestToolTip(const QModelIndex& index) { // only request a tooltip for the name column and when no selection or // drag & drop operation is done (indicated by the left mouse button) if ( !(QApplication::mouseButtons() & Qt::LeftButton) ) { d->tooltip->hide(); d->itemRect = d->view->visualRect(index); const QPoint pos = d->view->viewport()->mapToGlobal(d->itemRect.topLeft()); d->itemRect.moveTo(pos); d->item = index; d->timer->start(d->delay); } else { hideToolTip(); } } void ToolTipManager::hideToolTip() { d->timer->stop(); d->tooltip->hideLater(); } void ToolTipManager::prepareToolTip() { showToolTip( d->item ); } void ToolTipManager::showToolTip( const QModelIndex &menuItem ) { if (QApplication::mouseButtons() & Qt::LeftButton) { return; } QWidget * tip = createTipContent( menuItem ); d->tooltip->showBelow(d->itemRect, tip, d->view->nativeParentWidget()->windowHandle()); connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater); } QWidget * ToolTipManager::createTipContent( QModelIndex item ) { const QSize dialogIconSize = QSize(IconSize(KIconLoader::Dialog), IconSize(KIconLoader::Dialog)); const QSize toolbarIconSize = QSize(IconSize(KIconLoader::MainToolbar), IconSize(KIconLoader::MainToolbar)); QWidget * tipContent = new QWidget(); QGridLayout* tipLayout = new QGridLayout(); tipLayout->setAlignment( Qt::AlignLeft ); QLayout * primaryLine = generateToolTipLine( &item, tipContent, dialogIconSize, true ); primaryLine->setAlignment( Qt::AlignLeft ); tipLayout->addLayout( primaryLine, 0, 0, Qt::AlignLeft ); for ( int done = 0; d->view->model()->rowCount( item ) > done; done = 1 + done ) { QModelIndex childItem = d->view->model()->index( done, 0, item ); QLayout * subLine = generateToolTipLine( &childItem, tipContent, toolbarIconSize, false ); subLine->setAlignment( Qt::AlignLeft ); tipLayout->addLayout( subLine, done + 2, 0, Qt::AlignLeft ); } tipLayout->setVerticalSpacing( tipContent->fontMetrics().height() / 3 ); tipContent->setLayout( tipLayout ); if( d->view->model()->rowCount( item ) > 0 ) { QFrame * separatorLine = new QFrame( tipContent ); separatorLine->setFrameStyle( QFrame::HLine ); tipLayout->addWidget( separatorLine, 1, 0 ); } return tipContent; } QLayout * ToolTipManager::generateToolTipLine( QModelIndex * item, QWidget * toolTip, QSize iconSize, bool comment ) { // Get MenuItem MenuItem * menuItem = d->view->model()->data( *item, Qt::UserRole ).value(); QString text = menuItem->name(); if ( comment ) { text = QStringLiteral( "%1" ).arg( menuItem->name() ); } // Generate text if ( comment ) { text += QStringLiteral("
"); if ( !menuItem->service()->comment().isEmpty() ) { text += menuItem->service()->comment(); } else { int childCount = d->view->model()->rowCount( *item ); text += i18np( "Contains 1 item", "Contains %1 items", childCount ); } } QLabel * textLabel = new QLabel( toolTip ); textLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); textLabel->setForegroundRole(QPalette::ToolTipText); textLabel->setText( text ); // Get icon QPalette pal = textLabel->palette(); for (auto state : { QPalette::Active, QPalette::Inactive, QPalette::Disabled }) { pal.setBrush(state, QPalette::WindowText, pal.toolTipText()); pal.setBrush(state, QPalette::Window, pal.toolTipBase()); } privateIconLoaderSelf->self.setCustomPalette(pal); QIcon icon = KDE::icon(menuItem->service()->icon(), &privateIconLoaderSelf->self); QLabel * iconLabel = new QLabel( toolTip ); iconLabel->setPixmap( icon.pixmap(iconSize) ); iconLabel->setMaximumSize( iconSize ); // Generate layout QHBoxLayout * layout = new QHBoxLayout(); layout->setSpacing( textLabel->fontMetrics().height() / 3 ); layout->setAlignment( Qt::AlignLeft ); layout->addWidget( iconLabel, Qt::AlignLeft ); layout->addWidget( textLabel, Qt::AlignLeft ); return layout; } diff --git a/classic/CategoryList.cpp b/classic/CategoryList.cpp index df107e59..d9433e40 100644 --- a/classic/CategoryList.cpp +++ b/classic/CategoryList.cpp @@ -1,152 +1,152 @@ /* Copyright (c) 2000,2001 Matthias Elter Copyright (c) 2009 Ben Cooksley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "CategoryList.h" #include "systemsettings_classic_debug.h" #include "MenuItem.h" #include #include #include #include #include #include #include #include #include #include #include #include #include static const char kcc_infotext[]= I18N_NOOP("System Settings"); static const char title_infotext[]= I18N_NOOP("Configure your system"); static const char intro_infotext[]= I18N_NOOP("Welcome to \"System Settings\", " "a central place to configure your computer system."); class CategoryList::Private { public: Private() {} KHTMLPart * categoryView = nullptr; QModelIndex categoryMenu; QAbstractItemModel * itemModel = nullptr; QMap itemMap; }; CategoryList::CategoryList( QWidget *parent, QAbstractItemModel *model ) : QWidget(parent), d( new Private() ) { QHBoxLayout *mainLayout = new QHBoxLayout; setLayout(mainLayout); setMinimumSize( 400, 400 ); d->itemModel = model; // set what's this help this->setWhatsThis( i18n( intro_infotext ) ); d->categoryView = new KHTMLPart( this ); mainLayout->addWidget(d->categoryView->view()); d->categoryView->view()->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); d->categoryView->widget()->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ); connect( d->categoryView->browserExtension(), SIGNAL( openUrlRequest( const QUrl&, const KParts::OpenUrlArguments&, const KParts::BrowserArguments& ) ), this, SLOT(slotModuleLinkClicked(QUrl)) ); } CategoryList::~CategoryList() { delete d; } void CategoryList::updatePixmap() { QString content; QString moduleName; d->itemMap.clear(); const QString templatePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("systemsettings/classic/main.html") ); QFile templateFile( templatePath ); templateFile.open( QIODevice::ReadOnly ); QTextStream templateText( &templateFile ); QString templateString = templateText.readAll(); templateString = templateString.arg( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage.css") ) ); if ( qApp->layoutDirection() == Qt::RightToLeft ) { templateString = templateString.arg( QStringLiteral("@import \"%1\";") ).arg( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kf5/infopage/kde_infopage_rtl.css") ) ); } else { templateString = templateString.arg( QString() ); } templateString = templateString.arg( i18n( kcc_infotext ) ); templateString = templateString.arg( i18n( title_infotext ) ); templateString = templateString.arg( i18n( intro_infotext ) ); if ( d->categoryMenu.isValid() ) { moduleName = d->itemModel->data( d->categoryMenu, Qt::DisplayRole ).toString(); } - content += QStringLiteral("
") + moduleName + QStringLiteral("
"); + content += QLatin1String("
") + moduleName + QLatin1String("
"); content += QStringLiteral("\n"); for( int done = 0; d->itemModel->rowCount( d->categoryMenu ) > done; ++done ) { QModelIndex childIndex = d->itemModel->index( done, 0, d->categoryMenu ); MenuItem *childItem = d->itemModel->data( childIndex, Qt::UserRole ).value(); const QString url = QLatin1String("kcm:///") + childItem->item().fileName(); QUrl link(url); - const QString szLink = QStringLiteral(""); - content += QStringLiteral("\n"); } content += QStringLiteral("
") + szLink + QStringLiteral(""); + const QString szLink = QLatin1String(""); + content += QLatin1String("
") + szLink + QLatin1String(""); const QString szName = childItem->name(); const QString szComment = childItem->service()->comment(); - content += szLink + szName + QStringLiteral("") + szLink + szComment + QStringLiteral(""); + content += szLink + szName + QLatin1String("") + szLink + szComment + QLatin1String(""); //passing just the path is insufficient as some icon sets (breeze) only provide SVGs //instead pass data inline QIcon icon = QIcon::fromTheme(childItem->service()->icon()); QImage image(icon.pixmap(24).toImage()); //icons are hardcoded to size 24 above QByteArray byteArray; QBuffer buffer(&byteArray); image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); - content = content.arg(QStringLiteral("data:image/png;base64,") + iconBase64); + content = content.arg(QLatin1String("data:image/png;base64,") + iconBase64); d->itemMap.insert( link.url(), childIndex ); content += QStringLiteral("
"); d->categoryView->begin( QUrl::fromLocalFile( templatePath ) ); d->categoryView->write( templateString.arg( content ) ); d->categoryView->end(); } void CategoryList::changeModule( const QModelIndex &newItem ) { d->categoryMenu = newItem; updatePixmap(); } void CategoryList::slotModuleLinkClicked( const QUrl& moduleName ) { QModelIndex module = d->itemMap.value( moduleName.url() ); qCDebug(SYSTEMSETTINGS_CLASSIC_LOG) << "Link name: " << moduleName.url(); emit moduleSelected( module ); } #include "moc_CategoryList.cpp" diff --git a/core/MenuProxyModel.cpp b/core/MenuProxyModel.cpp index cee2cc23..852115c6 100644 --- a/core/MenuProxyModel.cpp +++ b/core/MenuProxyModel.cpp @@ -1,142 +1,142 @@ /************************************************************************** * Copyright (C) 2009 Ben Cooksley * * Copyright (C) 2007 Will Stephenson * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * * 02110-1301, USA. * ***************************************************************************/ #include "MenuProxyModel.h" #include "MenuItem.h" #include "MenuModel.h" MenuProxyModel::MenuProxyModel( QObject * parent ) : KCategorizedSortFilterProxyModel( parent ), m_filterHighlightsEntries( true ) { setSortRole( MenuModel::UserSortRole ); setFilterRole( MenuModel::UserFilterRole ); setFilterCaseSensitivity( Qt::CaseInsensitive ); } QHash MenuProxyModel::roleNames() const { QHash names = KCategorizedSortFilterProxyModel::roleNames(); names[KCategorizedSortFilterProxyModel::CategoryDisplayRole] = "categoryDisplayRole"; return names; } bool MenuProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const { if( isCategorizedModel() ) { return KCategorizedSortFilterProxyModel::lessThan( left, right ); } QVariant leftWeight = left.data( MenuModel::UserSortRole ); QVariant rightWeight = right.data( MenuModel::UserSortRole ); if ( leftWeight.toInt() == rightWeight.toInt() ) { return left.data().toString() < right.data().toString(); } return leftWeight.toInt() < rightWeight.toInt(); } bool MenuProxyModel::subSortLessThan( const QModelIndex &left, const QModelIndex &right ) const { if( isCategorizedModel() ) { QVariant leftWeight = left.data( MenuModel::UserSortRole ); QVariant rightWeight = right.data( MenuModel::UserSortRole ); if ( !leftWeight.isValid() || !rightWeight.isValid() ) { return KCategorizedSortFilterProxyModel::subSortLessThan( left, right ); } else { if ( leftWeight.toInt() == rightWeight.toInt() ) { return left.data().toString() < right.data().toString(); } else { return leftWeight.toInt() < rightWeight.toInt(); } } } return KCategorizedSortFilterProxyModel::subSortLessThan( left, right ); } bool MenuProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const { if (!m_filterHighlightsEntries) { return KCategorizedSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); } QModelIndex index = sourceModel()->index( source_row, 0, source_parent ); MenuItem * mItem = index.data( Qt::UserRole ).value(); // accept only systemsettings categories that have children - if ( mItem->children().isEmpty() && mItem->service()->serviceTypes().contains( QStringLiteral("SystemSettingsCategory") ) ) { + if ( mItem->children().isEmpty() && mItem->service()->serviceTypes().contains(QLatin1String("SystemSettingsCategory") ) ) { return false; } else { return true; // Items matching the regexp are disabled, not hidden } } void MenuProxyModel::setFilterHighlightsEntries (bool highlight ) { m_filterHighlightsEntries = highlight; } bool MenuProxyModel::filterHighlightsEntries() const { return m_filterHighlightsEntries; } Qt::ItemFlags MenuProxyModel::flags( const QModelIndex &index ) const { if ( !index.isValid() ) { return Qt::NoItemFlags; } QString matchText = index.data( MenuModel::UserFilterRole ).toString(); if( !matchText.contains( filterRegExp() ) ) { return Qt::NoItemFlags; } else { return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } } void MenuProxyModel::setFilterRegExp ( const QString & pattern ) { if (pattern == filterRegExp()) { return; } emit layoutAboutToBeChanged (); KCategorizedSortFilterProxyModel::setFilterRegExp( pattern ); emit layoutChanged (); emit filterRegExpChanged (); } QString MenuProxyModel::filterRegExp() const { return KCategorizedSortFilterProxyModel::filterRegExp().pattern(); } void MenuProxyModel::setFilterRegExp ( const QRegExp & regExp ) { emit layoutAboutToBeChanged (); KCategorizedSortFilterProxyModel::setFilterRegExp( regExp ); emit layoutChanged (); } diff --git a/sidebar/ToolTips/tooltipmanager.cpp b/sidebar/ToolTips/tooltipmanager.cpp index e806c865..49d53897 100644 --- a/sidebar/ToolTips/tooltipmanager.cpp +++ b/sidebar/ToolTips/tooltipmanager.cpp @@ -1,235 +1,235 @@ /******************************************************************************* * Copyright (C) 2008 by Konstantin Heil * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * *******************************************************************************/ #include "tooltipmanager.h" #include "MenuItem.h" #include #include #include #include #include #include #include #include #include #include #include #include class IconLoaderSingleton { public: IconLoaderSingleton() = default; KIconLoader self; }; -Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf); +Q_GLOBAL_STATIC(IconLoaderSingleton, privateIconLoaderSelf) class ToolTipManager::Private { public: Private() : tooltip(nullptr), view(nullptr), timer(nullptr), delay(300) { } KToolTipWidget *tooltip; QWidget* view; QAbstractItemModel *model; QTimer* timer; QModelIndex item; QRect itemRect; int delay; }; ToolTipManager::ToolTipManager(QAbstractItemModel *model, QWidget* parent) : QObject(parent) , d(new ToolTipManager::Private) { d->view = parent; d->model = model; d->tooltip = new KToolTipWidget(d->view); d->tooltip->setHideDelay(0); d->timer = new QTimer(this); d->timer->setSingleShot(true); connect(d->timer, &QTimer::timeout, this, &ToolTipManager::prepareToolTip); d->view->installEventFilter(this); } ToolTipManager::~ToolTipManager() { delete d; } bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { if (watched == d->view) { switch (event->type()) { case QEvent::Leave: case QEvent::MouseButtonPress: hideToolTip(); break; default: break; } } return QObject::eventFilter(watched, event); } void ToolTipManager::requestToolTip(const QModelIndex& index, const QRect &rect) { // only request a tooltip for the name column and when no selection or // drag & drop operation is done (indicated by the left mouse button) if ( !(QApplication::mouseButtons() & Qt::LeftButton) ) { d->tooltip->hide(); d->itemRect = rect; const QPoint pos = d->view->mapToGlobal(d->itemRect.topLeft()); d->itemRect.moveTo(pos); d->item = index; d->timer->start(d->delay); } else { hideToolTip(); } } void ToolTipManager::hideToolTip() { d->timer->stop(); d->tooltip->hideLater(); } void ToolTipManager::prepareToolTip() { // item may have gone away since we're triggered by a timer MenuItem * menuItem = d->model->data( d->item, Qt::UserRole ).value(); if (menuItem) { showToolTip( d->item ); } } void ToolTipManager::showToolTip( const QModelIndex &menuItem ) { if (QApplication::mouseButtons() & Qt::LeftButton) { return; } QWidget * tip = createTipContent( menuItem ); if (qApp->isRightToLeft()) { d->tooltip->showAt(d->itemRect.topLeft() - QPoint(d->tooltip->width(), 0), tip, d->view->nativeParentWidget()->windowHandle()); } else { d->tooltip->showAt(d->itemRect.topRight(), tip, d->view->nativeParentWidget()->windowHandle()); } connect(d->tooltip, &KToolTipWidget::hidden, tip, &QObject::deleteLater); } QWidget * ToolTipManager::createTipContent( QModelIndex item ) { const QSize dialogIconSize = QSize(IconSize(KIconLoader::Dialog), IconSize(KIconLoader::Dialog)); const QSize toolbarIconSize = QSize(IconSize(KIconLoader::MainToolbar), IconSize(KIconLoader::MainToolbar)); QWidget * tipContent = new QWidget(); QGridLayout* tipLayout = new QGridLayout(); tipLayout->setAlignment( Qt::AlignLeft ); QLayout * primaryLine = generateToolTipLine( &item, tipContent, dialogIconSize, true ); primaryLine->setAlignment( Qt::AlignLeft ); tipLayout->addLayout( primaryLine, 0, 0, Qt::AlignLeft ); for ( int done = 0; d->model->rowCount( item ) > done; done = 1 + done ) { QModelIndex childItem = d->model->index( done, 0, item ); QLayout * subLine = generateToolTipLine( &childItem, tipContent, toolbarIconSize, false ); subLine->setAlignment( Qt::AlignLeft ); tipLayout->addLayout( subLine, done + 2, 0, Qt::AlignLeft ); } tipLayout->setVerticalSpacing( tipContent->fontMetrics().height() / 3 ); tipContent->setLayout( tipLayout ); if( d->model->rowCount( item ) > 0 ) { QFrame * separatorLine = new QFrame( tipContent ); separatorLine->setFrameStyle( QFrame::HLine ); tipLayout->addWidget( separatorLine, 1, 0 ); } return tipContent; } QLayout * ToolTipManager::generateToolTipLine( QModelIndex * item, QWidget * toolTip, QSize iconSize, bool comment ) { // Get MenuItem MenuItem * menuItem = d->model->data( *item, Qt::UserRole ).value(); QString text = menuItem->name(); if ( comment ) { text = QStringLiteral( "%1" ).arg( menuItem->name() ); } // Generate text if ( comment ) { text += QStringLiteral("
"); if ( !menuItem->service()->comment().isEmpty() ) { text += menuItem->service()->comment(); } else { int childCount = d->model->rowCount( *item ); text += i18np( "Contains 1 item", "Contains %1 items", childCount ); } } QLabel * textLabel = new QLabel( toolTip ); textLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); textLabel->setForegroundRole(QPalette::ToolTipText); textLabel->setText( text ); // Get icon QPalette pal = textLabel->palette(); for (auto state : { QPalette::Active, QPalette::Inactive, QPalette::Disabled }) { pal.setBrush(state, QPalette::WindowText, pal.toolTipText()); pal.setBrush(state, QPalette::Window, pal.toolTipBase()); } privateIconLoaderSelf->self.setCustomPalette(pal); QIcon icon = KDE::icon(menuItem->service()->icon(), &privateIconLoaderSelf->self); QLabel * iconLabel = new QLabel( toolTip ); iconLabel->setPixmap( icon.pixmap(iconSize) ); iconLabel->setMaximumSize( iconSize ); // Generate layout QHBoxLayout * layout = new QHBoxLayout(); layout->setSpacing( textLabel->fontMetrics().height() / 3 ); layout->setAlignment( Qt::AlignLeft ); layout->addWidget( iconLabel, Qt::AlignLeft ); layout->addWidget( textLabel, Qt::AlignLeft ); return layout; }