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. Adding Widgets to widgets
QtWS25 Last Chance

Adding Widgets to widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 6.5k Views
  • 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by
    #1

    Is it possible to add widgets to a widget?

    Basically, widgets are added to the layout. I've done so in my coding but it does not give me the desired result.

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    Pl45m4P jsulmJ 2 Replies Last reply
    0
    • Swati777999S Swati777999

      Is it possible to add widgets to a widget?

      Basically, widgets are added to the layout. I've done so in my coding but it does not give me the desired result.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Swati777999

      You cant add a widget to a widget directly.

      The widget's content is organized in layouts, where you can have multiple sub-widgets.

      You can set a widget as parent of another and show it (floating) within parent widget's boundings, but that's not really "adding"


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • Swati777999S Swati777999

        Is it possible to add widgets to a widget?

        Basically, widgets are added to the layout. I've done so in my coding but it does not give me the desired result.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Swati777999 said in Adding Widgets to widgets:

        but it does not give me the desired result.

        Then please show the code and tell us what your desired result is and what you get...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        Swati777999S 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Swati777999 said in Adding Widgets to widgets:

          but it does not give me the desired result.

          Then please show the code and tell us what your desired result is and what you get...

          Swati777999S Offline
          Swati777999S Offline
          Swati777999
          wrote on last edited by Swati777999
          #4

          @jsulm

               int n=20;
              QGridLayout *mSDLayout = new QGridLayout();
              QMap <int,QWidget*>dTWidgets;
              QMap <int, QLabel*>Names;
              QMap <int ,QTableWidget *> dTs;
          
              FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
          
                for (int ii=0;ii<n;ii++)
                  {
          
                    dTWidgets[ii] =new QWidget();  
          
          //          mSDLayout->addWidget(dTWidgets[ii],0,ii);
                    mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
          
          
                    Names[ii] =new QLabel(QString("Name %1").arg(ii+1));
          
                    flowLayout->addWidget(Names[ii]);
                    flowLayout->setAlignment(Names[ii],Qt::AlignHCenter);
          
                    dTs[ii] = new QTableWidget(); 
                    flowLayout->addWidget(dTs[ii]);
                    dTWidgets[ii]->setLayout(flowLayout);
          

          This gives me following result [with inactive flowLayout functionality]
          SingleFLayout.PNG

          “ In order to be irreplaceable, one must always be different” – Coco Chanel

          jsulmJ 1 Reply Last reply
          0
          • Swati777999S Swati777999

            @jsulm

                 int n=20;
                QGridLayout *mSDLayout = new QGridLayout();
                QMap <int,QWidget*>dTWidgets;
                QMap <int, QLabel*>Names;
                QMap <int ,QTableWidget *> dTs;
            
                FlowLayout *flowLayout=new FlowLayout(); // Parent Layout
            
                  for (int ii=0;ii<n;ii++)
                    {
            
                      dTWidgets[ii] =new QWidget();  
            
            //          mSDLayout->addWidget(dTWidgets[ii],0,ii);
                      mSDLayout->addWidget(dTWidgets[ii],0,ii,Qt::AlignCenter);
            
            
                      Names[ii] =new QLabel(QString("Name %1").arg(ii+1));
            
                      flowLayout->addWidget(Names[ii]);
                      flowLayout->setAlignment(Names[ii],Qt::AlignHCenter);
            
                      dTs[ii] = new QTableWidget(); 
                      flowLayout->addWidget(dTs[ii]);
                      dTWidgets[ii]->setLayout(flowLayout);
            

            This gives me following result [with inactive flowLayout functionality]
            SingleFLayout.PNG

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Swati777999 said in Adding Widgets to widgets:

            dTWidgets[ii]->setLayout(flowLayout);

            Why?!

            Your dTWidgets widgets should be set in flowLayout, not other way around.

            Also, why do you use QMap instead of QVector?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            Swati777999S 1 Reply Last reply
            3
            • jsulmJ jsulm

              @Swati777999 said in Adding Widgets to widgets:

              dTWidgets[ii]->setLayout(flowLayout);

              Why?!

              Your dTWidgets widgets should be set in flowLayout, not other way around.

              Also, why do you use QMap instead of QVector?

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on last edited by Swati777999
              #6

              @jsulm

              Sorry to have put it here, this code was meant to be posted for FlowLayout Qs :
              For this Q

              “ In order to be irreplaceable, one must always be different” – Coco Chanel

              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