Unsolved how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget
-
Hi,
What OS are you on ?
What do you want to do with it ?
Are you thinking about the icon in the application window decoration ? -
Hello @SGaist,
I'm using with the Windows 10 operating system.
what I would like to do is that when you move the mouse over the icon it automatically enlarges the image of the icon itself -
@Domenico said in how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget:
enlarges the image of the icon itself
The way you describe it, it's not possible I guess. The MS Windows Icon has a fixed size
-
it is true that the icon has a fixed size. for this I would like that when you pass the mouse over the icon then MouseEvent and I will do so that when I receive signal from mouseEvent I make the image appear on another window with a larger image ... but when I pass the mouse over it is not detected the mouse event ... is there a way to receive event signal mouse on icon?
-
@Domenico said in how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget:
is there a way to receive event signal mouse on icon
In general this is possible but I dont know if it works with the QIcon as window icon inside the title bar (You cant access the Windows Title Bar directly)
https://doc.qt.io/qt-5/qwidget.html#windowIcon-prop
I dont know what happens, when you connect a signal (for testing) to your Icon and then set it as window icon...
If this works, you can filter e.g. MouseHover-Events to check if your mouse is over your icon, but as I said above, I dont know if the icon event fires from inside the Win Title Bar.How your solution looks like until now? Or is it this, what you have tried already? :)
-
@Domenico Please explain what you mean with "QMainWindow icon".
Is it some icon you place somewhere in your app? If so how do you show this icon? -
@Pl45m4 yes I have already tried and it didn't work probably I will have done something wrong in the code .. but with MouseHoverEvent I have not used it .. can you give me some examples?
-
I use it with ' setWindowIcon(QIcon("path to your image")); '. Was that what you meant?
-
@Domenico said in how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget:
Was that what you meant?
The "real" Window Icon in Title Bar or "an icon" somewhere in your code on your Widget...
@Domenico said in how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget:
yes I have already tried and it didn't work probably I will have done something wrong in the code .. but with MouseHoverEvent I have not used it
MouseHover was just an example of MouseEvent / filter.
If you've done it right, and you still recieve no signal from your Icon, after it was set as Window Icon, then it's not possible in Qt with Signals / Events...EDIT:
Nevermind, QIcon is not a QObject / QWidget... So it cant send signals at all... QPixmap / QImage can, butsetWindowIcon();
requires a QIcon.
-
the icon I meant is as you see the image below:
-
Check out this:
https://forum.qt.io/topic/45489/solved-add-custom-actions-for-menu-shown-upon-clicking-the-title-bar-iconThere is a menu that opens with a click on the TitleBar Icon. You can handle that, by using QWidget::nativeEvent. In your case, you dont even need to add some stuff to this menu, you only want the click to place your slot / function there to execute your Widget / Window, that shows your enlarged Icon / Image.
Quite complicated for such little effect :) Why it has to be a click on the Icon? You can show a bigger version of your app icon in something like an AboutDialog.
Edit: Only works on Windows OS. MacOS has its own nativeEvent-Messages (you have to alter the code for this) and on Linux AFAIK you cant access the TitleBars at all, cause they run in a separate program.
-
@Pl45m4
I tried to follow as from your advice. apparently it doesn't work in any way -
What exactly did not work?
-
@Pl45m4
with the two functions customContextMenuRequested and QWidget :: nativeEvent in no way takes the signals / slots -
Because you did the part, that didnt worked for him either.
Haven't tested it myself yet, but I think it should work.
You need some additional includes to access HWND.https://lists.qt-project.org/pipermail/interest/2013-June/007650.html
https://stackoverflow.com/questions/14048565/get-hwnd-on-windows-with-qt5-from-wid
-
worked using these codes as recommended by you with the method QMainWindow::nativeEvent:
HMENU sysMenu = ::GetSystemMenu((HWND) winId(),FALSE); if (sysMenu != NULL) { ::InsertMenuA(sysMenu,0,MF_STRING, IDM_VIEWIMAGEICONBOX, "View image icon");
//so that this action is inserted before the action close in the sequence of actions in //the system menu
}bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG *msg = static_cast<MSG *>(message);if (msg->message == WM_SYSCOMMAND) { if ((msg->wParam & 0xfff0) == IDM_VIEWIMAGEICONBOX) { // Show the view image icon dialog showImageIcon(); return true; } } return false;
}
thank you very much!!
-
The additional option inside the action menu was just from the old forums posting. I think you can do it without the menu too (only with click).
If you are happy with the result, it's fine :)