MouseEvent propagation Parent -> Child
-
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?
-
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?
-
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.
-
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.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.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(). -
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
-
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 :)