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

Icons not displayed properly in QMenu - Regression from 5.4.2 to 5.6.1

    XMLWordPrintable

Details

    • Fix Win theme: 6bb0bc73c809d1defdcedc31c4c464a129d3de4d (qtbase/5.6, 14.7.2016, 5.6.2)

    Description

      A menu is populated dynamically for offering a recent file list. Qt 5.6.1 does not resize properly the icons, they appear cropped. Qt 5.4.2 displays the icons properly.

      Static menus with icons (built from Qt Designer) do not suffer from this bug.

      The icons which were retrieved by QFileIconProvider have been investigated (sizes were listed and every pixmap saved to a PNG) and are not in cause.

      Here is a MCVE:

      #include <QApplication>
      #include <QMainWindow>
      #include <QFileIconProvider>
      #include <QMenuBar>
      #include <QIcon>
      
      
      int main(int argc, char *argv[])
      {
      	QApplication a(argc, argv);
      	QMainWindow w;
      
      	QFileIconProvider iconProvider;
      	QIcon icon = iconProvider.icon(QFileInfo("C:/Windows/explorer.exe"));
      	w.menuBar()->addAction(new QAction(icon, "Test", w.menuBar()));
      	w.show();
      
      	return a.exec();
      }
      

      The problem is somewhat fixed if I extract a PNG from the icon and recreate the icon:

      icon = QIcon(icon.pixmap(QSize(16,16)));
      icon = QIcon(icon.pixmap(QSize(32,32)));

      The QIcon has sizes 16x16 and 32x32. The system DPI setting in Windows 7 and Qt takes it as a device pixel ratio of 1.25
      The returned icon pixmaps are 20x20 and 40x40 but they have a devicePixelRatio of 1.0, whereas they should have 1.25

      When using a DPI setting of 100% in Windows 7 the issues does not appear anymore.

      Attachments

        1. iconmetric_samples.txt
          1 kB
          Friedemann Kleint
        2. iconmetrics.zip
          2 kB
          Friedemann Kleint
        3. nok-5-6-1.png
          18 kB
          Etienne Sandré-Chardonnal
        4. ok-5-4-1.png
          17 kB
          Etienne Sandré-Chardonnal
        5. QTBUG-54561.png
          3 kB
          Jesus Fernandez
        6. qtbug54561.zip
          2 kB
          Friedemann Kleint
        7. qtdiag.txt
          6 kB
          Etienne Sandré-Chardonnal
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            galinette Etienne Sandré-Chardonnal
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes