You can connect to the QHeader::sizeChange() signal and resize the section back if it doesn't fit within a specified range.
You can connect to the QHeader::sizeChange() signal and resize the section back if it doesn't fit within a specified range.
BrainB0ne (2nd January 2007)
set minimum width of your ListView and set column width in some ratio.
Qt Code:
void MainWindow::onResizeMyList() { m_myList->setMinimumWidth(150 ); int w = m_myList->width(); int colWidth = 20; m_myList->setColumnWidth(1,colWidth ); m_myList->setColumnWidth(2,colWidth ); m_myList->setColumnWidth(3,colWidth ); m_myList->setColumnWidth(4,colWidth ); m_myList->setColumnWidth(0,w-colWidth *4); }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]
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
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 ::..
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:
#define COLUMNTORESIZE 0 void MyListView::onSectionSizeChanged(int section, int oldSize,int newSize) { setUpdatesEnabled(false); if (section == COLUMNTORESIZE) { int w = 20; if (newSize < w) { setColumnWidth(COLUMNTORESIZE, w); } } setUpdatesEnabled(true); }To copy to clipboard, switch view to plain text mode
Last edited by BrainB0ne; 2nd January 2007 at 15:08.
..:: Still Standing Strong ::..
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.
Bookmarks