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
Forum Updated to NodeBB v4.3 + New Features

MouseEvent propagation Parent -> Child

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 7.7k 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.HilkJ Offline
    J.HilkJ Offline
    J.Hilk
    Moderators
    wrote on 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.

    jsulmJ 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      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?

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on 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.HilkJ 1 Reply Last reply
      1
      • jsulmJ jsulm

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

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on 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.

        jsulmJ 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

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

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on 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.HilkJ 1 Reply Last reply
          2
          • jsulmJ jsulm

            @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.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on 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
            • BjornWB Offline
              BjornWB Offline
              BjornW
              wrote on last edited by BjornW
              #6

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

              1 Reply Last reply
              1
              • J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on 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.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on 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

                  • Login

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