Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to implement a filling-space QAction's icon?
Limer last edited by Limer
Firstly, please take a look at the qt-creator's filling-space QAction's icon,
I draw a svg file, just as the below,
I used it as a QAction's icon, but when I ran my program, it looked that the icon didn't fill the space apparently.
The codes is as below,
QMenu* languagesMenu = menuBar->addMenu(tr("Languages")); connect(languagesMenu, &QMenu::triggered, this, &MainWindow::changeLanguageSlot); languagesMenu->addAction(QIcon(":/images/dot_hover.svg"), tr("(System Language)")); languagesMenu->addSeparator(); languagesMenu->addAction(tr("English")); languagesMenu->addAction(tr("Simplified Chinese"));
Why? Could someone give me any advice?
Question not very clear. Do you want the ICON or highlighter ?
@dheerendra ICON，The reason to move the mouse back and forth, just a habit, sorry for that.
I can see ICON in your UI. So what is the issue ?
@dheerendra Take a careful comparison between the pic1's icon and pic3's icon (the icons refer to the ones with blue background-color), the pic3's icon didn't fill all the space.
You are specifying only one ICON. Where is the pic3 icon ? I did not see the code to set the pic3 icon.
@Limer The blue rectangle in your first picture is not from the icon. It is the background of a checkable action when it is checked. The icon is actually smaller than that. It just has a transparent background so you can't see it.
To get the same effect just make the background of your icon transparent and leave only the black dot.
QAction* act = languagesMenu->addAction(QIcon(":/images/dot_hover.svg"), tr("(System Language)")); act->setCheckable(true); act->setChecked(true);
Btw. a dot is not a very good choice of icon for language setting. It looks more like a radio button. For language I would suggest something like a speech bubble or some letters.
@Chris-Kawa Yes, you are right, thanks very much.