Results 1 to 13 of 13

Thread: How to find which QTreeWidgetItem?

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to find which QTreeWidgetItem?

    Dear All

    We create a QTreeWidget with a SQL query. We bring all the values like
    Qt Code:
    1. q.exec("...");
    2. while(q.next())
    3. {
    4. QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
    5. cities->setText(0, tr(q.value(0).toString()));
    6. }
    To copy to clipboard, switch view to plain text mode 

    There is no problem with this one. But in the query in some row I have child on cities items.
    Qt Code:
    1. q.value(0).toString()
    To copy to clipboard, switch view to plain text mode 
    is not same in every row, so is it possible to find which item on the tree that I could add the child?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    You have to find the proper item based on the result of your query. Or maybe I don't understand the problem...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?

    problem is like this,
    query is like this
    1 New York
    2 Helena
    3 Salt Lake City

    the tree is like this
    id city
    1 New York
    2 Helena
    3 Salt Lake City

    the three is like this. but in the query I get a row like
    2.1 xxx
    2.2 yyy which I had to show

    2 Helena
    2.1 xxx
    2.2 yyy

    Or could be 2.2.1 in the query...

    Were I able to explain?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    Quote Originally Posted by aekilic View Post
    Were I able to explain?
    Not really. I know what a tree is, I don't know what you are having problems with.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?

    query is like this
    1 New York
    2 Helena
    3 Salt Lake City
    2.1 xxx 2
    3.1 uuu 3
    1.1 iiii 1
    2.2 yyy 2
    3.1.1 yuyu 3.1

    I know from the query what is the parent but I dont know how can I put it under parent in the tree in a while(q.next)

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    Pass a pointer to the parent item to the constructor of the child item instead of a pointer to the tree widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?

    Normaly in table we could put a new row and a item like

    insertRow, setitem...etc

    is there a possible way to insert a tree like that?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    There is QTreeWidgetItem::insertChild(), if it makes a difference for you not to pass the parent into the constructor of the child...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?

    then how can I find the index?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    index of what? The child? You can use addChild() instead of insertChild() to append it to the end of the parent's child list.

    Come on man... open the docs and at least browse through the API...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?

    I think I was not able to explain,

    It so clear that I create the tree

    1
    2
    3
    4


    thats is ok. And from the query I get values like
    1.2
    1.1
    4.1
    1.1.1
    1.1.4
    1.1.2
    1.1.3
    not with an order. What I am planing is when I get a value like(4.1) this, I should find the index for 4 and addChild for this item?

    The main problem is when I create the treewidget, we put every item with the same name. So after if you would like to add a child every item has the same name, so where to put? As I have said I should find 4 first ( that is my main problem) and after that i could either insert or add a child. And that is why I have asked you how can I find the index of the item

    I am looking for the docs since morning but wasnt able find something helpfull.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find which QTreeWidgetItem?

    Quote Originally Posted by aekilic View Post
    I am looking for the docs since morning but wasnt able find something helpfull.
    You should look more carefully then.

    QTreeWidget::findItems() to find by content, QTreeWidget::topLevelItem() to find by index.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find which QTreeWidgetItem?


Similar Threads

  1. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  2. Qt and VC++ instalation problem
    By gui.br in forum Installation and Deployment
    Replies: 6
    Last Post: 21st July 2009, 07:13
  3. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  4. GCC can't find QSqlDatabase!!
    By brevleq in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2007, 07:05
  5. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13: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.