PDA

View Full Version : Resize rows and cols in a Tablewidget



zorro68
11th February 2007, 10:59
I'm trying to programming a tablewidget with 50 rows (maximum) and i want that table resize its height to number of rows if rows are less than 6, and if rows are more than 5 table fixed its height to 6 rows (+header).

My code is (I dont know how to put this as a code windows, as i can see in other post):



void Sheet::resize()
{
tabla->resizeRowsToContents();
int rows=tabla->rowCount();
int rowalt=tabla->rowHeight(0);
int height;
QScrollBar *Hscrollbar=tabla->horizontalScrollBar();
QHeaderView *Hheader=tabla->horizontalHeader();
if (Hheader->count()<4)
Hheader->setResizeMode(QHeaderView::Stretch);

if (rows<6){
height=rows*rowalt+Hheader->height();
}else{
height=6*rowalt+Hheader->height();//+tabla->horizontalHeader()->heigth();
}
if (!Hscrollbar->isVisible())height=height + Hscrollbar->height();
tabla->setMinimumHeight(height);
}

But sometimes resize ok, sometimes bad (n-1 rows), sometimes n and a half rows.....

What happend?:confused:

Thanks

jpn
11th February 2007, 12:19
My code is (I dont know how to put this as a code windows, as i can see in other post)

Highlight the code and select the "#" from the editor, or wrap it inside [ code ]-tags by hand (without the spaces):

[ code ]
void func() {
}
[ /code ]

Please do so, it will make the code much more readable..

zorro68
11th February 2007, 12:32
Thanks jpn

I have made some changes to the code, but dont work correctly. Help please...