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. QListWidget dragDropMode = InternalMove except the 2 first

QListWidget dragDropMode = InternalMove except the 2 first

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.3k Views 1 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.
  • M Offline
    M Offline
    myoan
    wrote on last edited by
    #1

    Hello every one,

    In a QListWidget I've set dragDropMode = InternalMove so that the user can reorder elements in list.
    This works well however I would like to prevent the first 2 elements to be moved, they must always stay the two first, we cannot move them and we cannot place any element before/between them, reordering is allowed only within range (3, ... infinite)

    A solution would be to subscribe to the @dropEvent ( QDropEvent * event )@ and cancel the drag&drop action if it's not allowed but I don't know if this is possible. Something like event->acceptThisDrop(false) would be perfect haha!

    Something even more userfriendly would be to make it impossible to start any drag action with the two first elements nor terminate any drop action within the 1st and 2nd position.

    Any idea to do this as simple as possible?
    Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      Hi,

      I would use 2 QListWidgets and put those 2 items to one of them with drag-and-drop disabled.

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

        Hi,

        What about setting the item flags of the two first elements to Qt::NoItemFlags ?

        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
        • M Offline
          M Offline
          myoan
          wrote on last edited by
          #4

          Hi all and thanks :)

          I forgot to mention that one element at a time can be selected in this list, including the two first. I must forbid only drag&drop-ing these two but they must be clickable.

          @ckakman well, that would be a bit annoying to synchronize both list since the user can select one element

          @SGaist your solution disables the item completely, I cannot click them anymore and they are grey.

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

            Then use the appropriate combination like

            @Qt::ItemIsSelectable |Qt::ItemIsEnabled@

            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
            • M Offline
              M Offline
              myoan
              wrote on last edited by
              #6

              @item->setFlags( ItemIsEnabled | ItemIsSelectable | ItemIsUserCheckable );@ is nearly what I want.
              However, I can still drop other items at the place of the first two.

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

                Then maybe reimplement the drop event to "freeze" the portion of the widget where they reside

                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
                • C Offline
                  C Offline
                  ckakman
                  wrote on last edited by
                  #8

                  [quote author="myoan" date="1421401499"]Hi all and thanks :)

                  I forgot to mention that one element at a time can be selected in this list, including the two first. I must forbid only drag&drop-ing these two but they must be clickable.

                  ckakman well, that would be a bit annoying to synchronize both list since the user can select one element

                  [/quote]

                  I'd say just deselect items in one list when an item in the other list is selected. In a slot connected to itemActivated():
                  @
                  foreach( QListWidgetItem *item, ui->otherList->selectedItems() )
                  item->setSelected(false);
                  @

                  Repeat this for the other table as well. 4 lines of code in total in 2 slots plus connecting the signals.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    myoan
                    wrote on last edited by
                    #9

                    Hmmm thanks. I'll see what is easier to implement.

                    By the way, how could I detect a "drag&drop" operation?
                    I can't find any working signal warning me about this.

                    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