Results 1 to 11 of 11

Thread: hidden QListView column suddenly visible

  1. #1
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default hidden QListView column suddenly visible

    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
    Qt Code:
    1. addColumn("testcolumn");
    2. addColumn("testhiddencolumn", 0);
    3. hideColumn(1);
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. header()->setStretchEnabled(true,0);
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    Try using QListView::setResizeMode(QListView::LastColumn) or QListView::setResizeMode(QListView::AllColumns) instead of QHeader::setSretchEnabled().

  3. #3
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    Quote Originally Posted by edb
    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.

  5. #5
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    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?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: hidden QListView column suddenly visible

    Unfortunately hiding columns in Qt3 QListView is totally screwed up and there are many problems with that...

  8. #8
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    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?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: hidden QListView column suddenly visible

    Quote Originally Posted by edb
    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, ... } > ?

  10. #10
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    Or:

    Qt Code:
    1. class MyListViewItem : public QListViewItem
    2. {
    3. public :
    4. MyListViewItem(...);
    5. // etc.
    6.  
    7. QString data1 { return mData1; }
    8. QString data2 { return mData2; }
    9. private :
    10. QString mData1;
    11. QString mData2;
    12. };
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2006
    Location
    Genk, Belgium
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hidden QListView column suddenly visible

    I tried the following, 'id' being the section number of the column I want to hide:

    Qt Code:
    1. listview->setColumnWidthMode(id,Manual);
    2. listview->setColumnWidth(id,0);
    3. // preventing the column to show up again when neighbouring columns are resized:
    4. listview->header()->setResizeEnabled(false,id);
    To copy to clipboard, switch view to plain text mode 

    It seems to do the trick.

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 14:46

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.