Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget
Forum Updated to NodeBB v4.3 + New Features

how to use MouseEvent on the icon of the QMainWindow and not an QWidget of the centralWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    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 ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    D 1 Reply Last reply
    1
    • SGaistS SGaist

      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 ?

      D Offline
      D Offline
      Domenico
      wrote on last edited by
      #3

      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

      Pl45m4P 1 Reply Last reply
      0
      • D Domenico

        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

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #4

        @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


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        D 1 Reply Last reply
        1
        • Pl45m4P Pl45m4

          @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

          D Offline
          D Offline
          Domenico
          wrote on last edited by
          #5

          @Pl45m4

          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?

          Pl45m4P jsulmJ 2 Replies Last reply
          0
          • D Domenico

            @Pl45m4

            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?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #6

            @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? :)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            D 1 Reply Last reply
            1
            • D Domenico

              @Pl45m4

              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?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @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?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply
              1
              • Pl45m4P Pl45m4

                @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? :)

                D Offline
                D Offline
                Domenico
                wrote on last edited by
                #8

                @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?

                Pl45m4P 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @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?

                  D Offline
                  D Offline
                  Domenico
                  wrote on last edited by
                  #9

                  @jsulm

                  I use it with ' setWindowIcon(QIcon("path to your image")); '. Was that what you meant?

                  1 Reply Last reply
                  0
                  • D Domenico

                    @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?

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #10

                    @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, but

                    setWindowIcon();
                    

                    requires a QIcon.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Domenico
                      wrote on last edited by
                      #11

                      the icon I meant is as you see the image below:

                      0_1561726141549_Immagine.png

                      Pl45m4P 1 Reply Last reply
                      0
                      • D Domenico

                        the icon I meant is as you see the image below:

                        0_1561726141549_Immagine.png

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by Pl45m4
                        #12

                        @Domenico

                        Check out this:
                        https://forum.qt.io/topic/45489/solved-add-custom-actions-for-menu-shown-upon-clicking-the-title-bar-icon

                        There 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.


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        D 1 Reply Last reply
                        3
                        • Pl45m4P Pl45m4

                          @Domenico

                          Check out this:
                          https://forum.qt.io/topic/45489/solved-add-custom-actions-for-menu-shown-upon-clicking-the-title-bar-icon

                          There 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.

                          D Offline
                          D Offline
                          Domenico
                          wrote on last edited by
                          #13

                          @Pl45m4
                          I tried to follow as from your advice. apparently it doesn't work in any way

                          Pl45m4P 1 Reply Last reply
                          0
                          • D Domenico

                            @Pl45m4
                            I tried to follow as from your advice. apparently it doesn't work in any way

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by
                            #14

                            @Domenico

                            What exactly did not work?


                            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                            ~E. W. Dijkstra

                            D 1 Reply Last reply
                            0
                            • Pl45m4P Pl45m4

                              @Domenico

                              What exactly did not work?

                              D Offline
                              D Offline
                              Domenico
                              wrote on last edited by
                              #15

                              @Pl45m4
                              with the two functions customContextMenuRequested and QWidget :: nativeEvent in no way takes the signals / slots

                              Pl45m4P 1 Reply Last reply
                              0
                              • D Domenico

                                @Pl45m4
                                with the two functions customContextMenuRequested and QWidget :: nativeEvent in no way takes the signals / slots

                                Pl45m4P Offline
                                Pl45m4P Offline
                                Pl45m4
                                wrote on last edited by Pl45m4
                                #16

                                @Domenico

                                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


                                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                ~E. W. Dijkstra

                                D 1 Reply Last reply
                                0
                                • Pl45m4P Pl45m4

                                  @Domenico

                                  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

                                  D Offline
                                  D Offline
                                  Domenico
                                  wrote on last edited by Domenico
                                  #17

                                  @Pl45m4

                                  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!!

                                  Pl45m4P 1 Reply Last reply
                                  1
                                  • D Domenico

                                    @Pl45m4

                                    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!!

                                    Pl45m4P Offline
                                    Pl45m4P Offline
                                    Pl45m4
                                    wrote on last edited by
                                    #18

                                    @Domenico

                                    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 :)


                                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                    ~E. W. Dijkstra

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved