Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QHBoxLayout that contains two QTableWidget,no display in paintevent

QHBoxLayout that contains two QTableWidget,no display in paintevent

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephane78
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

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

        S Offline
        S Offline
        stephane78
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Show your code please. Layouts have nothing to do with the updates of QTableWidget when you change the number of rows.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply
          1
          • SGaistS SGaist

            Show your code please. Layouts have nothing to do with the updates of QTableWidget when you change the number of rows.

            S Offline
            S Offline
            stephane78
            wrote on last edited by stephane78
            #5

            @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();
            
            }
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                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.

                S Offline
                S Offline
                stephane78
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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 ?

                    S Offline
                    S Offline
                    stephane78
                    wrote on last edited by stephane78
                    #9

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

                    J.HilkJ 1 Reply Last reply
                    0
                    • S stephane78

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

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @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


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      S 1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk

                        @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

                        S Offline
                        S Offline
                        stephane78
                        wrote on last edited by
                        #11

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

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved