Skip to Content
Hands-On GUI Programming with C++ and Qt5
book

Hands-On GUI Programming with C++ and Qt5

by Lee Zhi Eng
April 2018
Intermediate to advanced
404 pages
8h 27m
English
Packt Publishing
Content preview from Hands-On GUI Programming with C++ and Qt5

Adding functionality to the Tree Widget

Next, let's move on to the Tree Widget. It is actually not that different from the List Widget. Let's take a look at the following code:

QTreeWidgetItem* treeItem = new QTreeWidgetItem; 
treeItem->setText(0, "My Test Item"); 
ui->treeWidget->addTopLevelItem(treeItem); 

It's pretty much the same as the List Widget, except we have to set the column ID in the setText() function. This is because the Tree Widget is somewhere between a List Widget and a Table Widget—it can have more than one column but can't have any rows.

The most obvious distinction between a Tree Widget and other view widgets is that all its items can contain children items, recursively. Let's look at the following code to see how we can ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ GUI Programming with Qt 4

C++ GUI Programming with Qt 4

Jasmin Blanchette, Mark Summerfield

Publisher Resources

ISBN: 9781788397827Supplemental Content