QHBoxLayout that contains two QTableWidget,no display in paintevent
-
Hi,
I have two QTableWidget in a QDialog.I insert row in the paintevent method of the Dialog and I do update in a slot that receive signals.the rows are well displayed.
if I put a QHBoxlayout that contains the two QTableWIdget I don't see anymore my rows. I have tryed with ui->horizontallayout->invalidate() after the update() but it doesn't display my rows (now I have removed the QHboxlayout)
is there any solution to display my inserted rows in my QTableWidget with a Layout that contains my two QTableWIdget ? -
Hi,
Why are you adding rows in the paintEvent ? It's not the place to do such kind of stuff.
-
Show your code please. Layouts have nothing to do with the updates of QTableWidget when you change the number of rows.
-
@SGaist I have moved my code, where I insert rows, outside the paintevent, and it works well without layout, and it doesn't work with a layout , that contains my QTableWidget
so the code is copyrighted but I give the slot that insert row :void DialogTransferts::Onrundownload(listfiles *lf) { downloadlist=lf; ui->tableWidgetDown->clearContents(); while(!ldownloaditems.isEmpty()) { TableWidgetFListItem *pli=ldownloaditems.at(0); ldownloaditems.removeAt(0); delete pli; } ldownloaditems.clear(); if(downloadlist&&downloadlist->count()) { for(int i=downloadlist->count()-1;i>=0;i--) { MyFichier *monFichier=downloadlist->at(i); TableWidgetFListItem *pli =new TableWidgetFListItem(monFichier,monFichier->nomSymbolique(),monFichier->taille(),ui->tableWidgetDown); ui->tableWidgetDown->insertRow(0); ui->tableWidgetDown->setCellWidget(0,0,(QWidget*)pli); ldownloaditems.append(pli); } } ui->tableWidgetDown->resizeRowsToContents(); this->update(); //ui->horizontalLayout->invalidate(); }
-
Might be a silly question: did you set the layout on your DialogTransferts widget ?
By the way, why use a QTableWidget at all since you are only using setCellWidget ? A QScrollArea might be enough.
-
With the method you are using, there's no row content per see since you are only putting widgets everywhere. Hence my question stays: why use a QTableWidget since you seem to have one column of widgets ?
-
@SGaist the class that I used derivates from QTableWidgetItem and QWidget so it is a QTableWidgetitem too. I have already used this class in another software and there isn't any problem with it.(it allows me to put a QPushButton with a bitmap in it)
-
The simplest way to create a button with a bitmap in it is using stylesheets. No need to make your own class for that:
QPushButton *myButton = new QPushButton(); myButton->setStyleSheet("QPushButton{border-image:url(:/myButtonIcon.bmp);"} myButton->show();
learned that by accidently reading through the whole entry of the docu about styleSheets.
Back than, that was a real facepalm moment for me.