[Qt-interest] QTableview complete sizehint

Linos info at linos.es
Thu Mar 19 11:36:01 CET 2009


Israel Brewster escribió:
> On Mar 14, 2009, at 6:30 AM, Linos wrote:
> 
>> Hello,
>>     i have a dialog with a tableview that populate data from a dynamic 
>> sql query,
>> so the size can vary greatly depending on the size of the returned data.
>>
>> Any times the default size for the dialog it is too large, with a too 
>> big last
>> column because of setStrechtLastSection(True) and many blank rows and 
>> other
>> times i have scrollbars for the width and the height.
>>
>> I have tried any methods of the QHeaderView of the table and the 
>> QTableView
>> itself to determine what it is the size the tableview has after the 
>> populated
>> data and resize the dialog but i can get the correct value, how could 
>> i do it?
> 
> I ended up with the following kludgy, but seemingly functional solution.
> 
> For the width:
> 
> int width=reportView->horizontalHeader()->length();
> width+=reportView->verticalHeader()->width();
> 
> and similarly for height:
> 
> int desiredHeight=reportView->verticalHeader()->length();
> desiredHeight+=reportView->horizontalHeader()->height();
> 
> If using these values to set the window size, keep in mind that the 
> window layout has a certain margin you need to take into account 
> (centralwidget->layout()->getContentsMargins(&leftMargin,&mainTopMargin,&rightMargin,&mainBottomMargin);), 
> and, of course, you need to add in the size of any other widgets you may 
> have, such as toolbars or close buttons. Also (hopefully obviously) you 
> want to sanity check those values to make sure you don't wind up with 
> something larger than the viewable area of the monitor. If there is a 
> better way of doing this, I'd love to hear it.
> 
> -----------------------------------------------
> Israel Brewster
> Computer Support Technician II
> Frontier Flying Service Inc.
> 5245 Airport Industrial Rd
> Fairbanks, AK 99709
> (907) 450-7250 x293
> -----------------------------------------------
> 
>>
>> Regards,
>> Miguel Angel.
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 

Thanks Israel,
	it is worth noting that when you can not satisfy the vertical or horizontal 
size (> screen size) you have to sum too reportView->verticalScrollBar().width() 
or reportView->horizontalScrollBar().height() and in my test when the scrollbar 
are visible still sum +3 (i dont know why).

Regards,
Miguel Angel.



More information about the Qt-interest-old mailing list