How to remove text section in QAction inside QMenu?
-
Hi all,
I'm creating a custom context menu for my application.
@
const static QColor colors[5] = { QColor(231,216,124,85), QColor(214,149,156,85), QColor(190,211,112,85), QColor(124,185,200,85), QColor(190,147,204,85) };
@@
QPixmap pixmap(16,16);
pixmap.fill(colors[colorIndex_]);
QMenu *selectColor = new QMenu(tr("Colors"), this);
selectColor->setIcon(QIcon(pixmap));QList<QAction *> colorList; for (int i = 0; i < 5; i++) { pixmap.fill(colors[i]); QAction *color = new QAction(QIcon(pixmap), "", this); color->setData(QVariant(i)); colorList.append(color); } selectColor->addActions(colorList); menu->addMenu(selectColor);
@
Using the code above, I tried to create a color selection menu with 16 by 16 icon only.
This works fine in Mac using Qt 5.3 but when I try the same code in Windows 7 using Qt 5.3,!http://i.imgur.com/4oKyHbc.jpg!
the menu show a separator and huge blank space to the right.
I'm not sure if this is a bug or some requirement for Windows UI guideline or something.
Does anyone know how to get rid of that blank space?
Thank you.
-
Hi,
Looks a bit fishy, can you try again with
@QAction *color = new QAction(QIcon(pixmap), QString(), this);@
to see if it changes something
-
[quote author="SGaist" date="1401490814"]Hi,
Looks a bit fishy, can you try again with
@QAction *color = new QAction(QIcon(pixmap), QString(), this);@
to see if it changes something[/quote]
Thanks for the suggestion.
I tried QString() as you've suggested and also 0 but didn't make any difference.
I think I'll just have to come up with some text to go along with the colors. -
In between you can show the color name.
I can't tell if it's a windows limitation, however you could check the "bug report system":http://bugreports.qt-project.org to see if it's something known