How to change icon size of the QMenu under Mac.
-
Could you please advise how to change icon size of an item in the QMenu under Mac?
I use QProxyStyle and overwriting its method pixelMetric. That works good under Win, but under Mac... Mac doesn't care about pixelMetric, exactly pixelMetric is not used under Mac.
-
Hi,
AFAIK, that can't be changed in OS X
-
Hi,
There is one interest think - if I use Qt4 library then icon size of the QMenu item is 22x22 (approximately), but if I use Qt5 then the size is 16x16. So system menu can be changed and this change is made by Qt sources…
For example:
TrayIcon.cpp
@#include <assert.h>
#include "trayicon.h"TrayIcon::TrayIcon(QObject parent /= 0*/)
: QSystemTrayIcon(parent)
, closeAction_(QIcon(":/Images/QuitIcon.png"), "", 0)
{
//QMenu item
closeAction_.setText(tr("close menu"));
trayIconMenu_.addAction(&closeAction_);
connect( &closeAction_, SIGNAL(triggered()), this, SLOT(closeMenu()));//QSystemTrayIcon setIcon((QIcon(":/Images/trayActivated.png"))); setContextMenu(&trayIconMenu_); setToolTip(tr("Test QMenu"));
}
void TrayIcon::closeMenu()
{
trayIconMenu_.close();
}@TrayIcon.h
@#ifndef trayicon_h_
#define trayicon_h_#include <QSystemTrayIcon>
#include <QMenu>class TrayIcon
: public QSystemTrayIcon
{
Q_OBJECT
Q_DISABLE_COPY(TrayIcon)
public:
explicit TrayIcon(QObject *parent = 0);signals:
public slots:
void closeMenu();private slots:
private:
QMenu trayIconMenu_; QAction closeAction_;
};
#endif@
main.cpp
@
#include <QScopedPointer>
#include "trayicon.h"QScopedPointer<TrayIcon> trayIcon(new TrayIcon());
trayIcon_->show();
@If this code is build using Qt4 or using Qt5 libraries then visual results are different:
!http://s17.postimg.org/qt06ti93v/QT4_QT5_Context_Menu.png(Qt4 and Qt5 context menu difference)! -
Ok, the system tray menu doesn't follow the same guidelines has a menu in the menu bar.
Can you tell exactly what you are trying to achieve ?
-
I try to get the pop-up context menu under Mac with the icon size 22x22 px approximately. I use QMenu class from the Qt5 for this library but in the result I have icon size 16x16 px approximately. And I cannot change the icon size…Any style settings doesn't impact icon size under Mac (against Windows). And OS is not the reason of small or big size of the icon. If I use QMenu from the Qt4 then icon size is 22x22 px.
On the same machine, under the same OS (Mac 10.9) Qt5 – 16x16px, Qt4 -22x22px, Qt5 - 16x16px, Qt4 - 22x22px.
Now I’m investigate source code of the QMenu in the Qt4 and Qt5 libraries. I’m looking for reason of the icon size changing. Maybe size is set anywhere in the QMenu class inside.
I cannot use 16x16 size because there is strong specification for application and it requires big size of the icon (22x22 or 20x20 px)
-
AFAIK, it set in the style. However, if you have special needs, you should maybe do it another way and create your own "popup" widget