Results 1 to 10 of 10

Thread: Drag & Drop multiselection on QTableWidget

  1. #1
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5

    Default Drag & Drop multiselection on QTableWidget

    Hi all!!

    I am developing an application with some qtablewidgets that are multi selection enabled. The point is that I need to avoid the drag & drop multiselection property from the tables. Is there any possibility to set this property to false for the QTableWidget?

    Thanks in advance!!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & Drop multiselection on QTableWidget

    Set the internalMove property of the widget to false. Same for dragEnabled.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5

    Default Re: Drag & Drop multiselection on QTableWidget

    Thanks for the reply wysota!

    I added these two sentences to the code but nothing change in the qtablewidget behavior:

    tblOutputs->setDragEnabled(false);
    tblOutputs->setDragDropMode(QAbstractItemView:ragDropMode(tblOutputs->dragDropMode() & ~QAbstractItemView::InternalMove));

    In fact, tblOutputs->dragDropMode() returns 0, so it seems that drag and drop is disabled, but it selects multiple rows dragging the mouse from the table while clicking left button. I do not know what´s the problem...

    Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & Drop multiselection on QTableWidget

    Ohhh.... you wanted to disable selection by dragging? I guess I misunderstood you then. In that case change selectionBehavior to something else than ExtendedSelection.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5

    Default Re: Drag & Drop multiselection on QTableWidget

    No, but I need to select multiple rows by clicking on items, but I do not need to select rows by dragging the mouse. I need to disable this behavior, but still continue selecting multiple rows by only clicking on items.

    Any idea??

    Thanks again!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & Drop multiselection on QTableWidget

    QAbstractItemView::SelectionMode -- see the different selection modes and choose which fits you best.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5

    Default Re: Drag & Drop multiselection on QTableWidget

    The problem is that both of the multiple-selection-options tips "Multiple items can be toggled by dragging the mouse over them". And what I don´t want to happen is exactly that behaviour, to select rows by dragging mouse.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & Drop multiselection on QTableWidget

    Then your only option is to prevent the view for getting and drag-like events at all by applying an event filter on the view's viewport and filtering out MouseMove events. Alternatively you can probably set the view to NoSelection mode and implement selection yourself the way you like it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    jbarrena (27th November 2014)

  10. #9
    Join Date
    Jul 2010
    Posts
    23
    Thanks
    5

    Default Re: Drag & Drop multiselection on QTableWidget

    Quote Originally Posted by wysota View Post
    Then your only option is to prevent the view for getting and drag-like events at all by applying an event filter on the view's viewport and filtering out MouseMove events. Alternatively you can probably set the view to NoSelection mode and implement selection yourself the way you like it.
    Thanks!

    I created a class inherited from QTableWidget and overwrite mouseMoveEvent. Thanks for your support!

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag & Drop multiselection on QTableWidget

    Just make sure it doesn't ruin scrolling the widget by dragging the scroll bar.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Drag & Drop rows in a QTableWidget
    By vycke in forum Qt Programming
    Replies: 7
    Last Post: 19th January 2012, 00:01
  2. Drag and drop reordering in a QTableWidget
    By Lendrick in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2009, 23:19
  3. Drag and Drop QTableWidget in UI file.
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 23:02
  4. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 09:33
  5. Drag & Drop using QTableWidget
    By Israa in forum Qt Programming
    Replies: 21
    Last Post: 12th April 2007, 19:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.