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. Starting Drag from QListWidget initiates Unwanted Selection
Forum Updated to NodeBB v4.3 + New Features

Starting Drag from QListWidget initiates Unwanted Selection

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 744 Views 2 Watching
  • 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    I have created the start of a drag action from a QListWidget. This QListWidget has selection mode ExtendedSelection, see also http://doc.qt.io/qt-4.8/qabstractitemview.html#SelectionMode-enum I would l like to keep this behavior except for the fact that it shouldn't do the selection behavior originating from drag events. How can I exclude selecting items by dragging with selection mode ExtendedSelection?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you mean by you *you created the start of a grad action" ? Aren't you using the already implemented in Qt's item view classes ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by ModelTech
        #3

        Here is the code for the QWidget where the QDrag starts

        void ClassList::mousePressEvent(QMouseEvent *Event) {
        
            if (Event->button() == Qt::LeftButton)
                DragStartPosition = Event->pos();
            QListWidget::mousePressEvent(Event);
        }
        
        void ClassList::mouseMoveEvent(QMouseEvent *Event) {
        
            if (Event->buttons() & Qt::LeftButton) {
                int Distance = (Event->pos() - DragStartPosition).manhattanLength();
                if (Distance >= QApplication::startDragDistance())
                    performDrag();
            }
            QListWidget::mouseMoveEvent(Event);
        }
        
        void ClassList::performDrag() {
        
            if (currentItem())
                if (currentItem()->foreground() == Qt::black) {
                    InstantiableItem *Current = static_cast<InstantiableItem *>(currentItem());
                    InstantiableMime *Mime = new InstantiableMime(Current->item());
                    Mime->setText(QString(Current->item()->name()));
                    QDrag *Drag = new QDrag(this);
                    Drag->setMimeData(Mime);
                    Drag->setPixmap(Current->icon().pixmap(QSize(20, 20)));
                    Drag->exec(Qt::MoveAction);
                }
        }
        

        InstantiableItem is my subclass of QListWidgetItem and InstantiableMine is my subclass of QMimeData. ClassList is a subclass of QListWidget.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I'd recommend rather implementing your own list model based on the drag and drop model described here.

          That will likely make your implementation simpler and cleaner.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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