Results 1 to 4 of 4

Thread: Filter Label for searching QTreeView

  1. #1
    Join Date
    Aug 2020
    Posts
    2
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default Filter Label for searching QTreeView

    Hello awesome qt community,

    I am new to qt and searching for a method to display predefined filters as a label/node (as in the attached screenshot, please ignore the colors ). They should be simply drag and dropable into a search filter. Besides the filter should also handle manual user inputs and if possible the labels should be simple to removed (for example with a small cross right from the label).
    Is there any kind of widget for such an approach?

    I hope it is somehow understandable what kind of function I am looking for.

    Thank you all in advance


    Screenshot from 2020-08-26 09-12-20.png.
    Last edited by Mac.0; 26th August 2020 at 09:40.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Filter Label for searching QTreeView

    Your question mentions QTreeView. Are these query terms represented in a hierarchical structure like a tree? What is the meaning when two terms appear on the same line? Does it mean a logical OR? ("2k" OR "4k" ?) And what is the meaning of each line? Are two lines a logical AND? (("2k" or "4k") AND ("action_essentials") ?)

    If not, then what is the point of a tree, and how will dragging and dropping be used to assemble a meaningful query?

    On Amazon's shopping search pages, when there are multiple versions / suppliers of a product, there -is- a tree-like structure of checkboxes and descriptive names, arranged into different categories. So there could be a "Supplier" category, with multiple choices within it. Each checkbox within a category is a logical OR. Between categories ("Supplier" and "Price range") is a logical AND (Supplier is ABC OR XYZ AND Price range is $100 - 200).

    Are you trying to do something like this, except graphically?

    If there is no hierarchy to your filter terms, then the tree structure doesn't sound like it would be appropriate. You might want to use something like a simple layout with QLabels instead. The Flow Layout example is a self-rearranging layout for arbitrarily-sized items in a rectangular region.

    Otherwise, I am not aware of any "out of the box" widget or layout that will do what you want.
    <=== 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.

  3. #3
    Join Date
    Aug 2020
    Posts
    2
    Thanks
    1
    Qt products
    Platforms
    Unix/X11

    Default Re: Filter Label for searching QTreeView

    thank you for the reply d_stranz.
    The QTreeView which should be queried by the search is not on the screenshot I uploaded (sorry for that). The position of the labels under the search bar has no meaning, they are predefined filters that should be drag and dropable into the search field. But if the user has an unique search which is not represented as Label it should be possible to write manually into the search bar.
    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?
    Last edited by Mac.0; 27th August 2020 at 11:44.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 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.

  5. 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, 18:16
  2. Searching a QListWidget
    By bl1nk in forum Newbie
    Replies: 11
    Last Post: 9th August 2010, 22:54
  3. QAbstractListModel searching.
    By ComaWhite in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 19:41
  4. Searching in a list.
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2008, 09:00
  5. Searching a QTable
    By nategoofs in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 23: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.