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 ?


  • Lifetime Qt Champion

    Hi,

    Why are you adding rows in the paintEvent ? It's not the place to do such kind of stuff.



  • @SGaist even if i add all my rows in the slot where I call update and then after I call update, I think there won't appear because of the Layout.is there anything to do with the layout like invalidate or update?


  • Lifetime Qt Champion

    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();
    
    }
    

  • Lifetime Qt Champion

    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.



  • @SGaist Ihave put a resizeRowsToContents(); at the beginning of the function and now it is ok I can see the rows...


  • Lifetime Qt Champion

    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)



  • @stephane78

    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.

    of course it was at the very last entry. HERE



  • @J.Hilk It allows me to put a button in a QTablewidgetItem,sorry my english is not perfect


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.