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

QDrag conflict with hover of widgets

    XMLWordPrintable

Details

    • Windows
    • 4f95e66f9 (dev), 3b3960c9b (6.7)

    Description

      When you start a drag using QDrag and during the drag you go on widgets with the mouse and drop outside them, at the end of the drag and drop action the hover style is still there, the user has to move the mouse on them to remove the hover style to get back to original style.
      The problem looks to be there only when QWidget:item:hover is in the stylesheet.
      Here a minimal code to reproduce the issue :
      The hover of the QLineEdit is red to have a good visual of the issue.
      Drag the test item on the line edit but drop outside once the mouse was on it.
      The red color still there until the mouse is on the line edit again.

      #include <QApplication>
      #include <QMainWindow>
      #include <QTreeWidget>
      #include <QVBoxLayout>
      #include <QLineEdit>
      
      class MainWindow : public QMainWindow
      {
      public:
          explicit MainWindow(QWidget* parent = 0)
          {
              QVBoxLayout* Layout = new QVBoxLayout;
              QTreeWidget* TreeWidget = new QTreeWidget;
              TreeWidget->setDragDropMode(QAbstractItemView::InternalMove);
              QTreeWidgetItem* TreeWidgetItem = new QTreeWidgetItem(TreeWidget);
              TreeWidgetItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEditable);
              TreeWidgetItem->setText(0, "Test");
              Layout->addWidget(new QLineEdit);
              Layout->addWidget(TreeWidget);
              QWidget* LayoutWidget = new QWidget;
              LayoutWidget->setLayout(Layout);
              setCentralWidget(LayoutWidget);
              setFocus();
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          a.setStyleSheet("QWidget:item:hover{background-color: lightblue;color: black;}"
                          "QLineEdit:hover{border: 1px solid red;}");
          MainWindow w;
          w.show();
          return a.exec();
      }
      

      Attachments

        1. qtbug50403.zip
          4 kB
          Irfan Omair
        2. 20230606_192232.mp4
          1.54 MB
          Irfan Omair
        For Gerrit Dashboard: QTBUG-50403
        # Subject Branch Project Status CR V

        Activity

          People

            vhilshei Volker Hilsheimer
            alundra Michael Ségura
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes