Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3785

[REG] Bug in QWidget::underMouse

    XMLWordPrintable

Details

    Description

      I have found a case in which QWidget::underMouse does not return a correct
      value.

      If you delete a widget and then another widget has the mouse under, if you
      don't move the mouse and ask if that new widget has the mouse under it says
      no.

      I attach an example code, there if i click on label 0 it will disappear and
      label 1 will take its place, if without moving the mouse you click the mouse
      again you will see it does not disappear even you really have the mouse over
      the widget.

      This is reproducible for me using Qt in X11 on KDE 4.2 not sure if that might
      work or not on Windows/Mac or some other X11 window manager.

      Example:

      #include <QApplication>
      #include <QDebug>
      #include <QLabel>
      #include <QVBoxLayout>

      class MyWidget : public QLabel
      {
      protected:
      void mousePressEvent(QMouseEvent *e)
      {
      if (underMouse())

      { delete this; }

      }
      };

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);

      QWidget *w = new QWidget();
      QVBoxLayout *l = new QVBoxLayout(w);
      l->setMargin(0);
      l->setSpacing(0);
      w->show();

      for (int i = 0; i < 5; ++i)

      { MyWidget *mw = new MyWidget(); mw->setFrameStyle(QFrame::Panel | QFrame::Raised); mw->setLineWidth(2); mw->setMinimumSize(50, 50); mw->setText(QString::number(i)); l->addWidget(mw); }

      return a.exec();
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bjnilsen Bjørn Erik Nilsen
            janichol Andy Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes