跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. Qt Development
  3. General and Desktop
  4. Using TreeWidgets
Forum Updated to NodeBB v4.3 + New Features

Using TreeWidgets

已排程 已置頂 已鎖定 已移動 General and Desktop
10 貼文 3 Posters 3.6k 瀏覽 1 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • A 離線
    A 離線
    Arukas
    寫於 最後由 編輯
    #1

    Hello-

    I'm use to using listView and having trouble with treeWidgets. Is there a way to get the TreeWidget to give you a simple index number like the listView does?

    -Thanks

    1 條回覆 最後回覆
    0
    • G 離線
      G 離線
      goetz
      寫於 最後由 編輯
      #2

      Being a hierarchical view, no, there is no such concept as an index here. I wouldn't make sense at all.

      Which API call do you refer when talking about "a simple index number"? Maybe there's something similar in the tree view...

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 條回覆 最後回覆
      0
      • A 離線
        A 離線
        Arukas
        寫於 最後由 編輯
        #3

        I can get row numbers from the tree, but that's doesn't really work because they start over when they go into a subtree. So how are you suppose to be able to tell which item is clicked on in these trees if their names aren't unique?

        1 條回覆 最後回覆
        0
        • G 離線
          G 離線
          goetz
          寫於 最後由 編輯
          #4

          The [[Doc:QTreeWidget]] signals contain a QTreeWidgetItem pointer, you can work on that. Isn't that sufficient?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 條回覆 最後回覆
          0
          • A 離線
            A 離線
            Arukas
            寫於 最後由 編輯
            #5

            Well, if I knew more about the QTreeWidgetItem, it might but as far as I can tell it only holds the a name, but my names are unique, so that causes a problem. How would I tell if I had the write pointer?

            1 條回覆 最後回覆
            0
            • A 離線
              A 離線
              andre
              寫於 最後由 編輯
              #6

              If you think it helps you, you could use a custom data role on your items and generate a unique ID number that you store in that role. You can then retreive that ID from the item when it is clicked. Reference the setData and data methods in QTreeWidgetItem.

              1 條回覆 最後回覆
              0
              • G 離線
                G 離線
                goetz
                寫於 最後由 編輯
                #7

                Sorry, I don't get the use case. What do you need that index for other than poking the correct item out of the view?

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 條回覆 最後回覆
                0
                • A 離線
                  A 離線
                  Arukas
                  寫於 最後由 編輯
                  #8

                  I just want to get the correct item out of the tree. Is the only way to use a

                  @map<QTreeWidgetItem, int>@

                  or does the treewidget do something like that already for you?

                  1 條回覆 最後回覆
                  0
                  • G 離線
                    G 離線
                    goetz
                    寫於 最後由 編輯
                    #9

                    If you take the QTreeWidget pointer delivered by the signals, you already HAVE the correct item.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 條回覆 最後回覆
                    0
                    • A 離線
                      A 離線
                      andre
                      寫於 最後由 編輯
                      #10

                      [quote author="Arukas" date="1328130428"]I just want to get the correct item out of the tree. Is the only way to use a

                      @map<QTreeWidgetItem, int>@

                      or does the treewidget do something like that already for you?

                      [/quote]

                      I posted a solution for that just above...

                      1 條回覆 最後回覆
                      0

                      • 登入

                      • Login or register to search.
                      • 第一個貼文
                        最後的貼文
                      0
                      • 版面
                      • 最新
                      • 標籤
                      • 熱門
                      • 使用者
                      • 群組
                      • 搜尋
                      • Get Qt Extensions
                      • Unsolved