PDA

View Full Version : hidden QListView column suddenly visible



edb
18th January 2006, 16:45
Hi all,

I need a listview with a visible and a hidden column. The hidden column should never become visible for the user as this is only used for coding issues.

I created a MyListView class derived from QListView with the following code in the constructor

addColumn("testcolumn");
addColumn("testhiddencolumn", 0);
hideColumn(1);

This has the following result: The listview shows two columns, namely the testcolumn and an empty column and the user is not able to view the testhiddencolumn even not when trying to resize the 0-width column.

As I wanted to use as much of the width of my listview, I wanted to make the column testcolumn use all the space in the listview, so I included the following line of code to the above constructor:


header()->setStretchEnabled(true,0);

This resulted in the testcolumn taking the entire width of the listview, but i got a strange site effect: When I dragged the column testcolumn-end in order to make the column smaller, the hidden column appeared and got larger. (it would be easy if I could show the result with some pictures, but don't know how to do that, they are not online...)

How can I prevent the hidden column from showing after using setStretchEnabled? I need to allow resizing of column testcolumn as I want to keep the size of this column synchronised to its contents.

I Tryed adding:
header()->setStretchEnabled(false, 1);
and/or:
header()->setResizeEnabled(false,1);
but none of both did the job.

Any ideas?

Chicken Blood Machine
18th January 2006, 17:35
Try using QListView::setResizeMode(QListView::LastColumn) or QListView::setResizeMode(QListView::AllColumns) instead of QHeader::setSretchEnabled().

edb
19th January 2006, 08:51
Tryed that, but it didn't work. The hidden column is imediately (without resizing an adjacent column first) visible then.

I use the function AdjustColumn(0) after renaming an item. Can this have anything to do with it?

Chicken Blood Machine
19th January 2006, 23:59
Tryed that, but it didn't work. The hidden column is imediately (without resizing an adjacent column first) visible then.

I use the function AdjustColumn(0) after renaming an item. Can this have anything to do with it?

Yes, I'm sure it does. hiding a column, just sets its width to 0. If you hide column 1, then call adjustColumn(0), then the width of column 0 will change to fit its text. If this means that it decreases, then of course the width of 1 will be forced to increase in order to take up the slack. This is true if the resizeMode is LastColumn or AllColumns.

edb
23rd January 2006, 10:44
Is it possible to set the resize mode of the last column to be false so that adjustColumn won't have any influence on the last column so that it stays hidden?

Chicken Blood Machine
23rd January 2006, 17:46
The resizemode applies to the whole table. You will have to manage the column widths manually if you need some special behaviour.

Why did you need this hidden column again anyway?

wysota
23rd January 2006, 19:32
Unfortunately hiding columns in Qt3 QListView is totally screwed up and there are many problems with that...

edb
24th January 2006, 10:35
Is QT4 better for working with hidden columns?
Is there another possibility of keeping information in a Listview for each item which may not be visible to the user, but must only be used in code?

wysota
24th January 2006, 11:25
Is there another possibility of keeping information in a Listview for each item which may not be visible to the user, but must only be used in code?

Maybe QMap<QListViewItem*, struct { QString f1, QString f2, ... } > ?

Chicken Blood Machine
24th January 2006, 16:56
Or:



class MyListViewItem : public QListViewItem
{
public :
MyListViewItem(...);
// etc.

QString data1 { return mData1; }
QString data2 { return mData2; }
private :
QString mData1;
QString mData2;
};

Pieter from Belgium
27th January 2006, 09:00
I tried the following, 'id' being the section number of the column I want to hide:



listview->setColumnWidthMode(id,Manual);
listview->setColumnWidth(id,0);
// preventing the column to show up again when neighbouring columns are resized:
listview->header()->setResizeEnabled(false,id);


It seems to do the trick.