Results 1 to 5 of 5

Thread: QTreeWidgetItem

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default QTreeWidgetItem

    Hello everybody
    QT:4.1.1

    I have a QTreeWidget where i can see my database and the tables of this.
    I was able to implement it. But i get a item there that i dont need (Please see picture).
    I dont need the selected one (picture).

    Can somebody see what is wrong on my code:
    Qt Code:
    1. ui.tree->clear();
    2. ui.tree->setObjectName(QLatin1String("ui.tree"));
    3. ui.tree->setHeaderLabels(QStringList(tr("database")));
    4. // ui.tree->header()->setResizeMode(QHeaderView::Stretch);
    5.  
    6. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    7. root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
    8. root->setText(0, "inventar");
    9.  
    10. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    11. tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/new.png")));
    12.  
    13. QSqlQuery select("select * from sysobjects where xtype = 'U' order by name");
    14. while(select.next())
    15. {
    16. QStringList tabelle = select.value(0).toStringList();
    17. new QTreeWidgetItem(tables, tabelle, 0);
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Think DigitalGasoline

  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: QTreeWidgetItem

    Don't create the "root" element.

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem

    of course
    thanks..
    Wysota how could i set a icon for every items in my list (parent tables):
    Qt Code:
    1. while(select.next())
    2. {
    3. QStringList tabelle = select.value(0).toStringList();
    4. new QTreeWidgetItem(tables, tabelle, 0);
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeWidgetItem

    Quote Originally Posted by raphaelf
    how to set a icon for every items in my list (parent tables)
    Exactly the same way you set the icon for the root/table item.
    Qt Code:
    1. QTableWidgetItem* item = new QTreeWidgetItem(tables, tabelle, 0);
    2. item->setIcon(..);
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QTreeWidgetItem

    Hi Guys
    Now i looks good!(enjoy pic)

    Qt Code:
    1. ui.tree->clear();
    2. ui.tree->setObjectName(QLatin1String("ui.tree"));
    3. ui.tree->setHeaderLabels(QStringList(tr("database")));
    4. // ui.tree->header()->setResizeMode(QHeaderView::Stretch);
    5.  
    6. QTreeWidgetItem *root = new QTreeWidgetItem(ui.tree);
    7. root->setIcon(0, QIcon(QString::fromUtf8(":/images/images/database.jpg")));
    8. root->setText(0, "inventar");
    9.  
    10. QTreeWidgetItem *tables = new QTreeWidgetItem(root);
    11. tables->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
    12. tables->setText(0, "tabellen");
    13.  
    14. QSqlQuery select("select * from sysobjects where xtype = 'U' order by name");
    15. while(select.next())
    16. {
    17. QString tabelle = select.value(0).toString();
    18. //new QTreeWidgetItem(tables, tabelle, 0);
    19. QTreeWidgetItem *items = new QTreeWidgetItem(tables);
    20. items->setText(0, tabelle);
    21. items->setIcon(0, QIcon(QString::fromUtf8(":/images/images/table.jpg")));
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    Think DigitalGasoline

Similar Threads

  1. hidden a QTreeWidgetItem
    By mattia in forum Newbie
    Replies: 6
    Last Post: 19th February 2014, 14:04
  2. Custom QTreeWidgetItem context menu?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 1st February 2010, 04:42
  3. PyQt remove the current QTreeWidgetItem
    By koenux in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2009, 23:08
  4. Replies: 3
    Last Post: 26th April 2008, 18:42
  5. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51

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.