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

Qt-interest Archive, June 2007
QHeaderView and updateGeometry()


Message 1 in thread

Hi,

I am trying to write a class derived from QTableView that supports multi-line 
strings in the horizontal header. After each header data change, it should 
update the horizontal header's height to allow the header string with the 
maximum number of lines to be fully displayed. I connected the signal 
headerDataChanged() of the model to a slot in the view which calls 
QHeaderView::updateGeometry(). Unfortunately, this only works sometimes. 
Under certain circumstances updateGeometry() does nothing. I checked the 
Qt-X11-4.3.0 source code and found out that it does some internal 
check "hasAutoResizeSections()" before resizing the header. 
Using the following hack, I could achieve the desired effect:

	horizontalHeader()->setStretchLastSection(true);  
	horizontalHeader()->updateGeometry();
	horizontalHeader()->setStretchLastSection(false); 

The first line makes sure hasAutoResizeSections() returns "true".

Now my question: Is the a more elegant/better way to do this?
My impression is that QHeaderView was not really made with multi-line header 
strings in mind. But before I post something in the task tracker I would like 
to hear someone else's opinion on this.

Best regards,
Tilman

--
 [ signature omitted ]