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. MouseEvent propagation Parent -> Child
QtWS25 Last Chance

MouseEvent propagation Parent -> Child

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 7.0k Views
  • 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.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 17 Feb 2017, 08:05 last edited by
    #1

    Hi,

    I made a custom FileDialog for my program, composed of a QWidget as the parent, 2 ListWidgets with custom Items, a couple of lineEdits and labels. All done through pure code, no designer was used.

    So far so good,

    using:

    cFileDialog *newDialog = new cFileDialog();
    newDialog->show();
    

    everything is fine.
    To integrate it into my main ui, I pass it an appropriate parent and add it to a layout:

    cFileDialog *newDialog = new cFileDialog(ui->SaveLoad);
    ui->gLaySaveLoad->addWidget(newDialog ,0,0,1,1);
    

    Now however the listwidgets don't seem to get the mouse events, e.g the Item under the mouse curser does not change its color. Clicking on the other side is correctly propagated.

    Any ideas on how to fix this issue?


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    J 1 Reply Last reply 17 Feb 2017, 08:40
    0
    • J J.Hilk
      17 Feb 2017, 08:05

      Hi,

      I made a custom FileDialog for my program, composed of a QWidget as the parent, 2 ListWidgets with custom Items, a couple of lineEdits and labels. All done through pure code, no designer was used.

      So far so good,

      using:

      cFileDialog *newDialog = new cFileDialog();
      newDialog->show();
      

      everything is fine.
      To integrate it into my main ui, I pass it an appropriate parent and add it to a layout:

      cFileDialog *newDialog = new cFileDialog(ui->SaveLoad);
      ui->gLaySaveLoad->addWidget(newDialog ,0,0,1,1);
      

      Now however the listwidgets don't seem to get the mouse events, e.g the Item under the mouse curser does not change its color. Clicking on the other side is correctly propagated.

      Any ideas on how to fix this issue?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 Feb 2017, 08:40 last edited by
      #2

      @J.Hilk Sounds like it is not a dialog.
      Did you implement mouseEvent in your widget?

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

      J 1 Reply Last reply 17 Feb 2017, 09:00
      1
      • J jsulm
        17 Feb 2017, 08:40

        @J.Hilk Sounds like it is not a dialog.
        Did you implement mouseEvent in your widget?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 17 Feb 2017, 09:00 last edited by
        #3

        @jsulm

        Originaly I had them not implemented, as I had no explicit/custom use for the events

        here an excerpt of my header:

        #include "clabel.h"
        #include <QObject>
        #include <QWidget>
        #include <QListWidget>
        #include <QLayout>
        #include <QLineEdit>
        #include <QLabel>
        
        class cFileDialog: public QWidget
        {
            Q_OBJECT
        public:
            explicit cFileDialog(QWidget *parent = 0);
        
            ~cFileDialog();
        
        protected:
            void resizeEvent(QResizeEvent *event);
            void mouseMoveEvent(QMouseEvent *event);
            void mouseDoubleClickEvent(QMouseEvent *event);
            void mousePressEvent(QMouseEvent *event);
            void mouseReleaseEvent(QMouseEvent *event);
            void enterEvent(QEvent *event);
            void leaveEvent(QEvent *event);
        
        ...
        ...
        ...
        }
        

        with a simple debug output to see what happens:

        void cFileDialog::mouseMoveEvent(QMouseEvent *event){
            qDebug() << "mouseMove"<<event->pos();
        }
        
        void cFileDialog::mouseDoubleClickEvent(QMouseEvent *event){
            qDebug() << "mouseDclick"<<event->pos();
        }
        
        void cFileDialog::mousePressEvent(QMouseEvent *event){
            qDebug() << "mousePress"<<event->pos();
        }
        
        void cFileDialog::mouseReleaseEvent(QMouseEvent *event){
            qDebug() << "mouseRelease"<<event->pos();
        }
        
        void cFileDialog::enterEvent(QEvent *event){
            qDebug() << "Enter";
        }
        
        void cFileDialog::leaveEvent(QEvent *event){
            qDebug() << "leave";
        }
        

        I get a mousemove event with every widget/Object but the two listwidgets.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        J 1 Reply Last reply 17 Feb 2017, 09:06
        0
        • J J.Hilk
          17 Feb 2017, 09:00

          @jsulm

          Originaly I had them not implemented, as I had no explicit/custom use for the events

          here an excerpt of my header:

          #include "clabel.h"
          #include <QObject>
          #include <QWidget>
          #include <QListWidget>
          #include <QLayout>
          #include <QLineEdit>
          #include <QLabel>
          
          class cFileDialog: public QWidget
          {
              Q_OBJECT
          public:
              explicit cFileDialog(QWidget *parent = 0);
          
              ~cFileDialog();
          
          protected:
              void resizeEvent(QResizeEvent *event);
              void mouseMoveEvent(QMouseEvent *event);
              void mouseDoubleClickEvent(QMouseEvent *event);
              void mousePressEvent(QMouseEvent *event);
              void mouseReleaseEvent(QMouseEvent *event);
              void enterEvent(QEvent *event);
              void leaveEvent(QEvent *event);
          
          ...
          ...
          ...
          }
          

          with a simple debug output to see what happens:

          void cFileDialog::mouseMoveEvent(QMouseEvent *event){
              qDebug() << "mouseMove"<<event->pos();
          }
          
          void cFileDialog::mouseDoubleClickEvent(QMouseEvent *event){
              qDebug() << "mouseDclick"<<event->pos();
          }
          
          void cFileDialog::mousePressEvent(QMouseEvent *event){
              qDebug() << "mousePress"<<event->pos();
          }
          
          void cFileDialog::mouseReleaseEvent(QMouseEvent *event){
              qDebug() << "mouseRelease"<<event->pos();
          }
          
          void cFileDialog::enterEvent(QEvent *event){
              qDebug() << "Enter";
          }
          
          void cFileDialog::leaveEvent(QEvent *event){
              qDebug() << "leave";
          }
          

          I get a mousemove event with every widget/Object but the two listwidgets.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 17 Feb 2017, 09:06 last edited by
          #4

          @J.Hilk From documentation (http://doc.qt.io/qt-5/QMouseEvent.html):
          "You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it."
          Since you do not handle the event you should call ignore().

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

          J 1 Reply Last reply 17 Feb 2017, 09:11
          2
          • J jsulm
            17 Feb 2017, 09:06

            @J.Hilk From documentation (http://doc.qt.io/qt-5/QMouseEvent.html):
            "You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it."
            Since you do not handle the event you should call ignore().

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 17 Feb 2017, 09:11 last edited by
            #5

            @jsulm

            I implemented the MoveEvent after I noticed the 'bug' when I give the class a parnet. They are usually not part of the class.

            To make sure, I added event->ignore(); to all functions and the behaviour is sadly still the same :(


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • B Offline
              B Offline
              BjornW
              wrote on 17 Feb 2017, 09:18 last edited by BjornW
              #6

              EDIT: Nevermind, I didn't read the question properly ^_^

              1 Reply Last reply
              1
              • J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 17 Feb 2017, 09:24 last edited by
                #7

                Mmmh,

                just made a new clean project, included my CLass and everything works as intendet.

                The problem ought to be somewhere else, mabe I have a global Stylesheet set somewhere or something. I'll check and update this topic appropriately


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 17 Feb 2017, 12:34 last edited by
                  #8

                  Of course, took me forever to find the problem.

                  The absolut top central Widget -QMainWindow- had the StyleSheet set to

                  background-color:white;
                  

                  That overwrote my custom widget.

                  Sometime its just 3 little words.....
                  I don't even remember writing them.

                  Anyway thanks all for your help :)


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  1

                  6/8

                  17 Feb 2017, 09:18

                  • Login

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