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 :)
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)
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.
Re: Set minimum columnwidth of QListView
set minimum width of your ListView and set column width in some ratio.
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);
}
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 :)
Re: Set minimum columnwidth of QListView
Quote:
Originally Posted by
wysota
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:
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);
}
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.