Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, August 2007
Sizing columns in QTreeView/QHeaderView (model/view)


Message 1 in thread

I'm trying to get my tree view column widths to be initially "properly"
space based on the lengths of the strings in the header and data fields.
I would also like to allow the user to re-size the column widths after
initial layout if, for  whatever reason, they don't like the initial 
"proper"
spacing.

So far, I've only been able to get one of "user re-sizable" or "properly
spaced" to work. Not both. Is there any way to get both?

I found the following information in the QHeaderView documentation:

void QHeaderView::setResizeMode(ResizeMode mode)
void QHeaderView::setResizeMode(int logicalIndex,ResizeMode mode)
enum QHeaderView::ResizeMode
    The resize mode specifies the behavior of the header sections. It 
    can be set on the entire header view or on individual sections using
    setResizeMode().
Constant                 Value Description
-------------------------------------------------------------------------------
QHeaderView::Interactive     0 The user can resize the section. The 
section can
                               also be resized programmatically using
                               resizeSection(). The section size defaults to
                               defaultSectionSize. (See also
                               cascadingSectionResizes.)
QHeaderView::Fixed           2 The user cannot resize the section. The 
section
                               can only be resized programmatically using
                               resizeSection(). The section size defaults to
                               defaultSectionSize.
QHeaderView::Stretch         1 QHeaderView will automatically resize the 
section
                               to fill the available space. The size 
cannot be
                               changed by the user or programmatically.
QHeaderView:ResizeToContents 3 QHeaderView will automatically resize the
                               section to its optimal size based on the
                               contents of the entire column or row. The 
size
                               cannot be changed by the user or
                               programmatically. (This value was introduced
                               in 4.2)

If I use QHeaderView:ResizeToContents, I get the columns to be well spaced
but then the user can't change them.

It sure would be nice if there was a:
QHeaderView:ResizeToContentsButUserModifiable resize mode.

But since there isn't, is there any other way to get the behavior I want?

--
 [ signature omitted ] 

Message 2 in thread

You may want QHeaderView::Interactive plus a persist data. Together, 
they work nicely.

 headerView->setResizeMode(QHeaderView::Interactive);

// Load
int size = getSectionSize(); // retrieve from DOM
if(size != -1) headerView->resizeSection(0, size);

// save
saveSectionSize(headerView->sectionSize(0)); // save to DOM, then to file

Cheers,
Lingfa

Peter Hackett wrote:

> I'm trying to get my tree view column widths to be initially "properly"
> space based on the lengths of the strings in the header and data fields.
> I would also like to allow the user to re-size the column widths after
> initial layout if, for  whatever reason, they don't like the initial 
> "proper"
> spacing.
>
> So far, I've only been able to get one of "user re-sizable" or "properly
> spaced" to work. Not both. Is there any way to get both?
>
> I found the following information in the QHeaderView documentation:
>
> void QHeaderView::setResizeMode(ResizeMode mode)
> void QHeaderView::setResizeMode(int logicalIndex,ResizeMode mode)
> enum QHeaderView::ResizeMode
>    The resize mode specifies the behavior of the header sections. It 
>    can be set on the entire header view or on individual sections using
>    setResizeMode().
> Constant                 Value Description
> ------------------------------------------------------------------------------- 
>
> QHeaderView::Interactive     0 The user can resize the section. The 
> section can
>                               also be resized programmatically using
>                               resizeSection(). The section size 
> defaults to
>                               defaultSectionSize. (See also
>                               cascadingSectionResizes.)
> QHeaderView::Fixed           2 The user cannot resize the section. The 
> section
>                               can only be resized programmatically using
>                               resizeSection(). The section size 
> defaults to
>                               defaultSectionSize.
> QHeaderView::Stretch         1 QHeaderView will automatically resize 
> the section
>                               to fill the available space. The size 
> cannot be
>                               changed by the user or programmatically.
> QHeaderView:ResizeToContents 3 QHeaderView will automatically resize the
>                               section to its optimal size based on the
>                               contents of the entire column or row. 
> The size
>                               cannot be changed by the user or
>                               programmatically. (This value was 
> introduced
>                               in 4.2)
>
> If I use QHeaderView:ResizeToContents, I get the columns to be well 
> spaced
> but then the user can't change them.
>
> It sure would be nice if there was a:
> QHeaderView:ResizeToContentsButUserModifiable resize mode.
>
> But since there isn't, is there any other way to get the behavior I want?
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>


--
 [ signature omitted ] 

Message 3 in thread

"Peter Hackett" <peter@xxxxxxxxxxxx> wrote in message 
news:46D8572A.6000707@xxxxxxxxxxxxxxx
> I'm trying to get my tree view column widths to be initially "properly"
> space based on the lengths of the strings in the header and data fields.
> I would also like to allow the user to re-size the column widths after
> initial layout if, for  whatever reason, they don't like the initial 
> "proper"
> spacing.
>
> So far, I've only been able to get one of "user re-sizable" or "properly
> spaced" to work. Not both. Is there any way to get both?
>
> I found the following information in the QHeaderView documentation:

You can call the function QTreeView::resizeColumnToContents(int)
when filling the tree.  Then the user can resize by dragging the headers 
around.
I don't think there's a setting to do this automatically though.


--
 [ signature omitted ]