Results 1 to 5 of 5

Thread: problem with tree view

  1. #1
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with tree view

    Hi all,
    tree.png
    I am new to Qt programming. Can some body explain how to do it? It looks like tree with buttons as Items. Do I have to use QTreeWidget ?

    Thanks in Advance,
    Prasanna Bhat

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem with tree view

    here is a sample QTreeWidget from a static sqlite3 my own sqlplug-in ... adapter...

    Qt Code:
    1. /* Compose the tree to pick the item from adressess */
    2. void Shop_Main::Compose_Addo()
    3. {
    4. /* addo_tree->clear(); QTreeView QMouseEvent #include <QTreeView><QTreeWidget> */
    5. AddoLoad.clear();
    6. bool attrib;
    7. QString daten;
    8. current_addo_item->setText("");
    9. addo_tree->setMouseTracking(true);
    10. addo_tree->clear();
    11. QStringList countrys = Query_List_Unique(QString( "SELECT DISTINCT land_code FROM %1 order by land_code" ).arg( TABLE_ADDO ));
    12. QStringListIterator i(countrys);
    13. while (i.hasNext()) {
    14. QString coustr = i.next().toLocal8Bit().constData();
    15. QTreeWidgetItem *cou = new QTreeWidgetItem(addo_tree);
    16. cou->setText(0,coustr);
    17. cou->setToolTip (0,tr("Open to Browse."));
    18. addo_tree->expandItem(cou);
    19. QStringList paese = Query_List_Unique(QString( "SELECT DISTINCT ort FROM %1 WHERE land_code='%2' order by ort" ).arg( TABLE_ADDO , coustr));
    20. QStringListIterator o(paese);
    21. while (o.hasNext()) {
    22. QString pas = o.next().toLocal8Bit().constData();
    23. QTreeWidgetItem *paeort = new QTreeWidgetItem(cou);
    24. paeort->setText(0,pas);
    25. paeort->setToolTip (0,tr("Open to Browse."));
    26. paeort->setIcon(0, QIcon(QString::fromUtf8(":/img/img/folder.png")));
    27. resultMap relist = Query_Qmap_Report(QString( "SELECT firma, name, id FROM %1 WHERE ort='%2' and land_code='%3' order by name" ).arg( TABLE_ADDO , pas , coustr));
    28. resultMap::Iterator it;
    29. for ( it = relist.begin(); it != relist.end(); ++it ) {
    30. QStringList roxe = it.value();
    31. int dbid;
    32. QString na = roxe.at(0).toLocal8Bit().constData();
    33. QString nb = roxe.at(1).toLocal8Bit().constData();
    34. QString inte = roxe.at(2).toLocal8Bit().constData();
    35. if (is_numeric(inte)) {
    36. bool ok;
    37. dbid = inte.toInt(&ok);
    38. } else {
    39. dbid = 0;
    40. }
    41. int clientid = CLIENT_BASE + dbid;
    42. attrib = CheckAttributes(dbid);
    43. if (attrib) {
    44. daten =QString("[%3] %1 %2 -si" ).arg(na , nb , QString::number(clientid) );
    45. } else {
    46. daten =QString("[%3] %1 %2 -no" ).arg(na , nb , QString::number(clientid) );
    47. }
    48.  
    49. QTreeWidgetItem *sigle = new QTreeWidgetItem(paeort);
    50. AddoLoad.append(daten);
    51. sigle->setText(0,daten);
    52. sigle->setIcon(0,QIcon(QString::fromUtf8(":/img/img/ooo-calc.png")));
    53. connect(addo_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(Safari()));
    54. QApplication::processEvents();
    55. }
    56. }
    57. }
    58.  
    59. }
    60.  
    61. /* this is a slot to get value ... */
    62.  
    63.  
    64. /* Discovery actived item to grab on db */
    65. void Shop_Main::Safari()
    66. {
    67. int xcol = addo_tree->currentColumn();
    68. QString findertree = addo_tree->currentItem()->text(xcol);
    69. int total = AddoLoad.size();
    70. if (total > 0) {
    71. QStringListIterator i(AddoLoad);
    72. while (i.hasNext()) {
    73. QString itemtext = i.next().toLocal8Bit().constData();
    74. if (itemtext == findertree) {
    75. current_addo_item->setText(itemtext);
    76. }
    77. }
    78. }
    79. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with tree view

    Quote Originally Posted by boss_bhat
    I am new to Qt programming. Can some body explain how to do it? It looks like tree with buttons as Items. Do I have to use QTreeWidget ?
    QTreeWidget won't look like this, you could write your own widget that will hold a number of QPushButtons and draw lines between them. It should be fairly easy to do.

  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: problem with tree view

    Or use QCanvas (Q3Canvas or a port of QCanvas to Qt4 available from Trolltech ftp server) or even code it yourself. It should be quite easy too, especially if you don't need the rectangles to be actually buttons.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with tree view

    Quote Originally Posted by patrik08
    Qt Code:
    1. QStringListIterator i(AddoLoad);
    2. while (i.hasNext()) {
    3. QString itemtext = i.next().toLocal8Bit().constData();
    4. if (itemtext == findertree) {
    5. current_addo_item->setText(itemtext);
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Why do you covert a QString to QByteArray, just to convert it back to QString?

    Why don't you just write:
    Qt Code:
    1. while( i.hasNext() ) {
    2. QString itemtext( i.next() );
    3. if( itemtext == findertree ) {
    4. current_addo_item->setText( itemtext );
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. tree view!!
    By Seema Rao in forum Qt Programming
    Replies: 4
    Last Post: 9th May 2006, 14:09
  2. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  3. Replies: 6
    Last Post: 20th April 2006, 10:23
  4. View update problem
    By prakash in forum Qt Programming
    Replies: 6
    Last Post: 17th March 2006, 10:13
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.