PDA

View Full Version : problem with tableWidget resizeRowsToContents



eugenesm
1st February 2010, 13:39
I have a problem with auto resize rows. On a form two QTableWidgets, with 4 columns, and a button. Constructor and button have same code. But result is different. Below is code with problem, with some changes (for example change columns count) it works properly), but i can't understand where is problem...



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

fillTable(ui->tableWidget);
}

void MainWindow::on_pushButton_clicked()
{
fillTable(ui->tableWidget_2);
}

void MainWindow::fillTable(QTableWidget *tableWidget)
{

tableWidget->setColumnWidth(0,30);
tableWidget->setColumnWidth(1,200);
tableWidget->setColumnWidth(2,50);
tableWidget->setColumnWidth(3,330);

QTableWidgetItem *wi;


int rownum = tableWidget->rowCount();
tableWidget->setRowCount(tableWidget->rowCount()+1);

wi = new QTableWidgetItem("1");
tableWidget->setItem(rownum,0,wi);

wi = new QTableWidgetItem("");
wi->setToolTip("");
tableWidget->setItem(rownum,1,wi);

QString s= "158";
wi = new QTableWidgetItem(s);
wi->setToolTip(s);
tableWidget->setItem(rownum,2,wi);

s= "asdg asdgd agjdj sgjagjsdgj asgdjadg wudi agdu da uidgwgau sdgyugayu gwdyua wd wad awugyd uadyu awydg yw dag dayds asjd ajdajsd sa jdjas djas djasd as"
"retuer uthwuie huirohwuerh wewer asejr jhb rjh ajkrkjhr uiworu howuiroah ruar ioauh iouao ui u uia uui wiuer iawu riuawi ruiawriawu hruiaw "
"aewuh riauwh riuawhi ruhawuirhawuirh uishfj ijsdhf kasjf d kfjashe lelk a7f8 73 8fw378 8wfrwofe bfseb jsbf js bsj sjbf sj fjsb fjsfj sfjs bjbf jsfj s fsj fsj f";
wi = new QTableWidgetItem(s);
wi->setToolTip(s);
tableWidget->setItem(rownum,3,wi);

tableWidget->resizeRowsToContents();
}



ps. sorry for my english