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. Custom qtreeview
Qt 6.11 is out! See what's new in the release blog

Custom qtreeview

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I need some guidance here on how to possibly implement the following custom
    qtreeview.

    Suppose I have QTreeView with say 4 columns

    @A
    B
    |-C checkbox checkbox checkbox
    |-D checkbox checkbox checkbox
    E
    F
    |-G checkbox checkbox checkbox
    |-H checkbox checkbox checkbox
    |-I checkbox checkbox checkbox
    |-J checkbox checkbox checkbox@

    1.I want to be able to say click on an item in the first column and allow it
    to be edited to another name EXCEPT if is A,B,E or F (any top level item) but any other item
    such as C,D,G,H, etc. can be edited to a new name. Additionally, I want to be able to click
    on a checkbox and change its setting.

    1. How can I get the pointer back to my derived QTreeViewItem so that i can then
      apply them to the underlying data?

    Thanks for any help.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

      If you can use QTreeWidget the following should work. QTreeWidget is a subclass of QTreeView so everything the widget can, the view also is able to but maybe with a bit more programming effort.

      You can use
      @
      item = new QTreeWidgetItem();
      tree->addItem(item);
      @

      to add a new item to the tree. By giving a parent you can build your hierarchy. After that you can set your own widget for the item with
      @

      tree->setItemWidget(item, 0, new MyWidget());
      @

      I am not sure which methods you can use with the QTreeView but as I wrote before you can write all of them yourself if necessary.

      You can get you widget back with

      @
      QList<QTreeWidgetItem *> selected = tree->selectedItems(); //or if you want to use the mouse pos
      tree->itemAt(x, y);
      @

      EDIT
      You use the flags to make the items editable or whatever:

      @
      item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
      @

      Be aware that for example if you parent item is not enabled you cannot select the child for example.

      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