PDA

View Full Version : Simple Table View



ruda
22nd March 2011, 03:51
I'm translating a little app that I made in PHP-Gtk to Qt. I was going well till I had to do what in Gtk is a GtkTreeView, but in Qt I guess it's a QTableView or a QTableWidget, I don't know which one to use. Basically it has 3 columns (Accounts, Password, Group Id) and must have the option to sort the items asc/desc. Here is a pic of my app:

http://img04.imgland.net/aB23Ojk2mE.jpg

If you double-click any item, the entries below will be filled according to the item you cliked.
If you click Prev/Next buttons, it will clear the list and add the new items.

I'm really lost because:
1. I dont know what is better to my case: QTableView or QTableWidget
2. I couldn't test any of both, since I didn't find any simple example to newbies

So... could someone show me how to do a simple table like in the pic? All the examples I found were difficult.

Thanks

PS: (I just want the table, forget the other widgets)

ChrisW67
22nd March 2011, 08:05
Please edit your post and upload the image to this site before a moderator finds and deletes it.

Where is the data in the table coming from? Is it fixed or variable?

ruda
22nd March 2011, 16:09
Please edit your post and upload the image to this site before a moderator finds and deletes it.

Where is the data in the table coming from? Is it fixed or variable?

From a variable. A friend told me to use QTreeView instead of QTables, but I'm still lost...

ChrisW67
22nd March 2011, 22:05
You can use either. The QTableView can source its data from any Qt data model (you might look a QStandardItemModel). The QTableWidget is a QTableView with its own internal data model. Search for Model/View Programming in the Qt documentation to get an overview of how this works.

To use the QTableWidget need to insert your values using QTableWidget::setItem(). You create and remove rows in the table with QTableWidget::insertRow() and QTableWidget::removeRow(). You enable sorting with setSortingEnabled(). You can used the currentChanged() signal from the QTableWidget's selectionModel() to trigger updates of the other widgets.