Qt World Summit: Submit your Presentation

MouseEvent propagation Parent -> Child

  • Moderators


    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,


    cFileDialog *newDialog = new cFileDialog();

    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?

  • Lifetime Qt Champion

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

  • Moderators


    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
        explicit cFileDialog(QWidget *parent = 0);
        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.

  • Lifetime Qt Champion

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

  • Moderators


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

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

  • Moderators


    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

  • Moderators

    Of course, took me forever to find the problem.

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


    That overwrote my custom widget.

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

    Anyway thanks all for your help :)

Log in to reply