Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-72212

QPushButton sizing and drawing problems with mac style

    XMLWordPrintable

Details

    • macOS

    Description

      Sometime between 5.6.9 and 5.11.2, drawing of QPushButtons with certain properties when using Mac style was (seemingly) broken.

      In the examples below, the top two buttons are regular QPushButtons, the first has text and the second does not. Those look fine. The third is a simple QPushButton subclass called HoverPushButton that is intended to be a sort of hybrid between a flat QPushButton and a QToolButton. It's definition is as follows:

      HoverPushButton::HoverPushButton(QWidget* parent) :
      	QPushButton(parent)
      {
      	setFlat(true);
      	setMaximumSize(26, 26);
      	setMinimumSize(26,26);
      	setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
      	setAttribute(Qt::WA_Hover, true);
      }
      
      // Protected.
      void HoverPushButton::paintEvent(QPaintEvent *event) {
      	QStyleOptionButton opt;
      	initStyleOption(&opt);
      	const bool currentFlat = isFlat();
      	const bool newFlat = (opt.state & QStyle::State_Enabled) ? !(opt.state & QStyle::State_MouseOver) : true;
      	if (currentFlat != newFlat) {
      		// This will force an update which will call paintEvent again.
      		setFlat(newFlat);
      	}
      
      	QPushButton::paintEvent(event);
      }
      

      Qt 5.9.6:

      Qt 5.12.0 (looks the same with 5.11.2):

      You can build the test application that I will attach to reproduce this problem.

      The screenshots above and test application demonstrate several problems. In both I've hovered over the button so you can see how it looks when hovered:

      1. The size of the text in the button with Qt 5.12 is much to small.
      2. The button itself is too small. It should be 26x26 pixels. It's close to that in height, but nowhere near that in width.
      3. If you run the example application and look closely as you move the cursor on and off the button, you'll notice that the position of the text shifts by a few pixels between the hovered and non-hovered states. This doesn't happen with Qt 5.9.6 and is distracting, particularly if you display an icon in the button instead of text.

      If I use Fusion style I don't see any of these problems.

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            tpochep Timur Pocheptsov
            aclight Adam Light
            Votes:
            5 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes