PDA

View Full Version : QtListView



Nazgul
20th March 2011, 13:47
Hello,

I'm trying to make a listview like this one

URL removed

You can see

Colum,Colum,Colum
45 45 45

or what numbers, I would like to make it in Qt, I don't know how many items so I've to make a function which do this do. As last thing I would like to have grid lines, so it's easy to see what belongs to what.

I googled and found out that QListView don't supports more than 1 column, but QtTableView is with a 1 for the item etc.

thanks for reading,

Nazgul
20th March 2011, 19:24
Sorry for the picture, not that important.

But I found out that I should use a TableView. Or TableWidget, what is the real difference between those?

I also found out that I need rows to add items, I would like to have none, ani ideas?

lynchkp
20th March 2011, 19:38
The TableView requires you to input your own data model as specified by the model/view framework. This is overkill for your application probably. The TableWidget provides a nice simple way to construct a table with a default model.

About a quarter of the way down this page is a good example. Here, you create QTableWidgetItems and add them to the TableWidget. It's pretty simple and fast.

Order Form Example

Nazgul
20th March 2011, 20:17
thanks, that works.

Now I'm trying to add item, but I've to make a row, is it possible to make the row invisible or just left out of it.

Or can I use the row just as value of the first column?

EDIT: seems only 1 row can I've specific item, is it possible to have more?

ChrisW67
20th March 2011, 21:49
Now I'm trying to add item, but I've to make a row, is it possible to make the row invisible or just left out of it.
Or can I use the row just as value of the first column?

Forgive me, but what is the point of adding a row to the table if you only want to hide it? You can hide a row in the view with QTableView::setRowHidden().

A row is a set of columns. How do you propose to put a set of columns into a single column?

Perhaps you mean a row number? You can use the vertical header that is provided by default, which displays row numbers, or provide your own header values (including an empty string).

EDIT: seems only 1 row can I've specific item, is it possible to have more?
I have no idea what you mean here. You can have as many rows as memory will allow. Every cell of every row can have whatever value you would like. Every header for a row (column) can have whatever value you would like.

Nazgul
20th March 2011, 21:56
Forgive me, but what is the point of adding a row to the table if you only want to hide it? You can hide a row in the view with QTableView::setRowHidden().

A row is a set of columns. How do you propose to put a set of columns into a single column?

Perhaps you mean a row number? You can use the vertical header that is provided by default, which displays row numbers, or provide your own header values (including an empty string).

I have no idea what you mean here. You can have as many rows as memory will allow. Every cell of every row can have whatever value you would like. Every header for a row (column) can have whatever value you would like.

Sorry for my bad english + not well telling.

Anyways I get this error in debug mode.


QTableWidget: cannot insert an item that is already owned by another QTableWidget
That is what i ment with my edit.

In win32 you could use CreateWindowEx() to create a listview, then add items to it, there were no rows

_ __| colum1 colum2
row1
row2

// I would like to get rid of the row things before, but keep the value from colum1 and colum2 there.

wysota
20th March 2011, 22:02
tableWidget->verticalHeader()->hide();
Is that what you want?

Nazgul
20th March 2011, 22:15
tableWidget->verticalHeader()->hide();
Is that what you want?

thanks that worked:)

Now gotta find a solution to that other problem, ideas?

ChrisW67
20th March 2011, 22:25
The other warning message is probably coming from using the same QTableWidgetItem several times in calls to setItem(). If you want to add three cells each containing the same value you should create three separate QTableWidgetItems with the same value and add those.

If that is not what you are doing then you will need to show the offending code.

Nazgul
21st March 2011, 07:29
Ye, you're right (again), thanks I used twice the QTableWidgetItem.

Could be closes now.