PDA

View Full Version : Set minimum columnwidth of QListView



BrainB0ne
29th November 2006, 10:59
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 :)

bood
21st December 2006, 02:40
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)

wysota
21st December 2006, 09:54
You can connect to the QHeader::sizeChange() signal and resize the section back if it doesn't fit within a specified range.

rajesh
22nd December 2006, 11:06
set minimum width of your ListView and set column width in some ratio.



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);

}

BrainB0ne
2nd January 2007, 11:32
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 :)

BrainB0ne
2nd January 2007, 14:11
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:



#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);
}

wysota
2nd January 2007, 15:25
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.