Results 1 to 4 of 4

Thread: Filter Label for searching QTreeView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Filter Label for searching QTreeView

    The flow layout seems to go into the right direction. But is it possible to drag and drop? And if the Label is dropped onto the search bar removed from the flow layout and re added if removed from the search bar?
    You have control over that. Look at the Qt Fridge Magnets example and the Draggable Icons example. Don't get hung up in the excessive detail, just try to get the concepts about how drag and drop work.

    It is probably important to understand that you are not dragging and dropping the QLabel itself, you are creating a QDrag instance that contains QMimeData that represents the item you are dragging. So if you are selecting a QLabel for the drag, your mime data will contain the QLabel's text (and you might add the pixmap to the QDrag if your label also has an icon). This QDrag instance and its data is what is passed in the drag / drop event.

    There was a long thread here recently which talked about drag and drop in list widgets, and how moving vs copying was handled. In this case, two QStringListModel instances were used to contain the strings in each of the list widgets. Flags returned by the model told whether copying and / or moving could happen.

    So if you decide you want to implement move semantics (dragging and dropping moves a label / string from one window to another), then you will have to also implement creating and destroying QLabel instances as part of that. When a label is dropped, you will have to destroy the old instance and create a new one.

    Look at the thread I referred to. It might be easiest to represent your filter terms in a QStringListModel, because the model will automatically handle the drag and drop and will send signals as it changes. The rowsRemoved() signal tells you that a string has been removed, and the rowsInserted() signals tells you when a string was added (dropped). You can then update your QLabels or whatever you choose to display the strings.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    Mac.0 (28th August 2020)

Similar Threads

  1. Replies: 2
    Last Post: 21st January 2016, 17:16
  2. Searching a QListWidget
    By bl1nk in forum Newbie
    Replies: 11
    Last Post: 9th August 2010, 21:54
  3. QAbstractListModel searching.
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 18:41
  4. Searching in a list.
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2008, 08:00
  5. Searching a QTable
    By nategoofs in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 22:15

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
  •  
Qt is a trademark of The Qt Company.