2

I had a working program in Qt4. After porting it to Qt5, the QActions' icons no longer show in the QMenu; only the text shows. The icons show ok in the toolbar, but not in the menu. I've already set the app to disable "AA_DontShowIconsInMenus" to no avail. Here is a portion of the code:

pMenuBar = new QMenuBar(this);
pMenuBar->setObjectName(QString::fromUtf8("Menu Bar"));
pMenuBar->setGeometry(QRect(0, 0, 800, 27));
MyIcon.addFile(":/images/filenew.ico", QSize(), QIcon::Normal, QIcon::On);
pAction = new QAction(tr("&New"), this);
pAction->setIcon(MyIcon);
pAction->setIconVisibleInMenu(true);
pAction->setShortcuts(QKeySequence::New);
pAction->setStatusTip(tr("New"));
pMenuFile = new QMenu(pMenuBar);
pMenuFile->setObjectName(QString::fromUtf8("File Menu"));
// pMenuFile->menuAction()->setIconVisibleInMenu(true);
pMenuFile->addAction(pAction);
pMenuBar->addAction(pMenuFile->menuAction());
setMenuBar(pMenuBar);
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
DrewD
  • 21
  • 3
  • Do you see your "File Menu" at all? setObjectName will set QObject Name property but not the menu title... Also which OS are you using? – Xplatforms May 13 '20 at 08:54
  • @Xplatforms, yes the file menu works just fine. The OS is Fedora 32 & Gnome desktop. – DrewD May 15 '20 at 12:48

1 Answers1

1

I guess *.ico is not supported, try it with *.png.

You can check: QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats()

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
  • I changed all of my QIcons to be sourced from PNG files and unfortuanately it made no difference whatsoever. Keep in mind this used to work in Qt4. The icons display fine in the toolbar but not in the menus. – DrewD May 15 '20 at 12:45
  • Well it doesn't work on mine. Here's my qtdiag results: Qt 5.13.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.0.1 20200311 (Red Hat 10.0.1-0.9)) on "xcb" OS: Fedora 32 (Workstation Edition) [linux version 5.6.6-300.fc32.x86_64] – DrewD May 18 '20 at 15:02