Results 1 to 7 of 7

Thread: Set minimum columnwidth of QListView

  1. #1
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Question Set minimum columnwidth of QListView

    Hallo Guys/Ladies,

    I have a (very simple) question, but i dind't find a solution yet, maybe you can help me.
    Is it possible to set a minimumsize of a particular column in a QListView?

    So when the column is resized by dragging the columnseparator the column should not become smaller than the minimum size I want the column to be.

    Thanks in advance
    ..:: Still Standing Strong ::..

  2. #2
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: Set minimum columnwidth of QListView

    Not seeing this kind of function...
    Maybe you can subclass QListView and re-implement some function to support this?(I don't know whether setColumnWidth will be ok)
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

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

    Default Re: Set minimum columnwidth of QListView

    You can connect to the QHeader::sizeChange() signal and resize the section back if it doesn't fit within a specified range.

  4. The following user says thank you to wysota for this useful post:

    BrainB0ne (2nd January 2007)

  5. #4
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 25 Times in 24 Posts

    Default Re: Set minimum columnwidth of QListView

    set minimum width of your ListView and set column width in some ratio.

    Qt Code:
    1. void MainWindow::onResizeMyList()
    2. {
    3. m_myList->setMinimumWidth(150 );
    4. int w = m_myList->width();
    5. int colWidth = 20;
    6. m_myList->setColumnWidth(1,colWidth );
    7. m_myList->setColumnWidth(2,colWidth );
    8. m_myList->setColumnWidth(3,colWidth );
    9. m_myList->setColumnWidth(4,colWidth );
    10. m_myList->setColumnWidth(0,w-colWidth *4);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 22nd December 2006 at 18:07. Reason: changed [html] to [code]

  6. #5
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Set minimum columnwidth of QListView

    Thank you for your answers, i almost forgot the purpose for this piece of functionality... I almost dealt with it, that it wasn't possible, but i'm going to play around with these suggestions within some days.

    Thank you all
    ..:: Still Standing Strong ::..

  7. #6
    Join Date
    Jan 2006
    Location
    Netherlands
    Posts
    56
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    10
    Thanked 2 Times in 2 Posts

    Default Re: Set minimum columnwidth of QListView

    Quote Originally Posted by wysota View Post
    You can connect to the QHeader::sizeChange() signal and resize the section back if it doesn't fit within a specified range.
    This solution works! but it doesn't look that nice... my listview is flickering a lot because of the paint events that occur. I called the setUpdatesEnabled(false) on the header and listview before setting back the section size... and after i called setUpdatesEnabled(true) but it keeps flickering.

    this is the code i use in the slot where sizeChange(int,int,int) is connected to:

    Qt Code:
    1. #define COLUMNTORESIZE 0
    2. void MyListView::onSectionSizeChanged(int section, int oldSize,int newSize)
    3. {
    4. setUpdatesEnabled(false);
    5.  
    6. if (section == COLUMNTORESIZE)
    7. {
    8. int w = 20;
    9.  
    10. if (newSize < w)
    11. {
    12. setColumnWidth(COLUMNTORESIZE, w);
    13. }
    14. }
    15.  
    16. setUpdatesEnabled(true);
    17. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by BrainB0ne; 2nd January 2007 at 15:08.
    ..:: Still Standing Strong ::..

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

    Default Re: Set minimum columnwidth of QListView

    You could take a look at QHeader::resizeSection() to see how it is implemented. Unfortunately it's not virtual, so you can't simply reimplement it, but maybe you can reimplement some method which is used by resizeSection() to constrain the dimensions.

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 13:46
  2. Key Events for QListView
    By bmesing in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2006, 09:29
  3. .gif and .tiff image type in QListView in QT3.3.5
    By darpan in forum Qt Programming
    Replies: 5
    Last Post: 18th March 2006, 04:31
  4. QT4 minimum requirements Debian GNU/Linux Sarge
    By Everall in forum Installation and Deployment
    Replies: 10
    Last Post: 21st February 2006, 12:21
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 14:45

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
  •  
Qt is a trademark of The Qt Company.