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
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