[Development] [OS X]: native classes (widgets) used for QTabBar and QTabWidget?

René J.V. Bertin rjvbertin at gmail.com
Fri Dec 11 11:53:40 CET 2015

Olivier Goffart wrote:

> On Tuesday 8. December 2015 21:38:10 René J. V. Bertin wrote:
>> If I may, do you also know how it is determined whether or not push buttons
>> should show icons or not? There's no equivalent to
>> Qt::AA_DontShowIconsInMenus and I'm also trying to understand why certain
>> KF5 applications (using kdelibs4support) always show icons in buttons [snip]

> I believe you are looking for QStyle::SH_DialogButtonBox_ButtonsHaveIcons,
> which is false for mac.

Is it even possible for QPushButtons to show an icon on OS X, or does the Mac drawing style simply ignore any icons on buttons? If so, on all buttons or only on those in a QDialogButtonBox (i.e. those that can have an icon added automatically as a function of their role)?

The code does seem to be a bit ambiguous about that style hint SH_DialogButtonBox_ButtonsHaveIcons. Is there a reason NOT to use this hint to turn off drawing of all button icons in a context (like KDE's) where there is a setting (ShowIconsOnPushButtons) that is intended to apply to all buttons?

More generally, is there a reason NOT to give this hint this kind of a general application to all buttons in Qt itself (and thus ultimately rename it, or provide a corresponding Qt:AA_xxx attribute)? I can only think of 1: buttons created with only an icon, but it is trivial to to include to override a false ButtonsHaveIcons hint if button->text.isEmpty(). For instance:

--- a/qtbase/src/widgets/widgets/qpushbutton.cpp
+++ b/qtbase/src/widgets/widgets/qpushbutton.cpp
@@ -332,8 +332,13 @@ void QPushButton::initStyleOption(QStyleOptionButton *option) const
     if (!d->flat && !d->down)
         option->state |= QStyle::State_Raised;
     option->text = d->text;
-    option->icon = d->icon;
-    option->iconSize = iconSize();
+    if (option->text.isEmpty() || style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) {
+        option->icon = d->icon;
+        option->iconSize = iconSize();
+    } else {
+        option->icon = QIcon();
+        option->iconSize = QSize(0,0);
+    }
 void QPushButton::setAutoDefault(bool enable)
@@ -398,20 +403,20 @@ QSize QPushButton::sizeHint() const
     // calculate contents size...
+    QString s(text());
+    bool empty = s.isEmpty();
 #ifndef QT_NO_ICON
     bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget())
                           && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons);
-    if (!icon().isNull() || showButtonBoxIcons) {
+    if (!icon().isNull() && (showButtonBoxIcons || empty)) {
         int ih = opt.iconSize.height();
         int iw = opt.iconSize.width() + 4;
         w += iw;
         h = qMax(h, ih);
-    QString s(text());
-    bool empty = s.isEmpty();
     if (empty)
         s = QString::fromLatin1("XXXX");
     QFontMetrics fm = fontMetrics();

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20151211/b1e0e749/attachment.html>

More information about the Development mailing list