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. [Solved] How can I change default expand/collapse sub-items in QTreeWidget?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How can I change default expand/collapse sub-items in QTreeWidget?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k 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.
  • L Offline
    L Offline
    LeeMinh
    wrote on last edited by
    #1

    I tried to create a simple treeview with the following code with Qt 4.8

    @
    QTreeWidgetItem *city = new QTreeWidgetItem(ui->trvCompetitions);
    city->setText(0, tr("City"));

    (new QTreeWidgetItem(city))->setText(0, tr("Stockholm"));
    (new QTreeWidgetItem(city))->setText(0, tr("Helsinki"));
    (new QTreeWidgetItem(city))->setText(0, tr("Copenhagen"));
    
    QTreeWidgetItem *other = new QTreeWidgetItem(ui->trvCompetitions);
    other->setText(0, tr("Other"));
    
    (new QTreeWidgetItem(other))->setText(0, tr("London"));
    (new QTreeWidgetItem(other))->setText(0, tr("Tokio"));
    (new QTreeWidgetItem(other))->setText(0, tr("Hanoi"));
    

    @

    And this is the treeview I got

    !http://i249.photobucket.com/albums/gg220/HienBoo/tree_view_1.png(myTreeView)!

    I have read "this article":http://qt-project.org/doc/qt-4.8/itemviews-simpletreemodel.html and I only want my treeview has expand/collapse sub-items like that

    !http://qt-project.org/doc/qt-4.8/images/simpletreemodel-example.png(The TreeView I want to get)!

    How can I change my treeview like this?

    Thank!

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

      http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtreeview

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeeMinh
        wrote on last edited by
        #3

        Oh, thanks for your reponse! It is useful for me.
        [quote author="butterface" date="1375969446"]http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtreeview[/quote]

        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