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. QGridlayout - problem while adding multiple layouts
Forum Updated to NodeBB v4.3 + New Features

QGridlayout - problem while adding multiple layouts

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 2.1k 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    Hi

    I am working on a weather forecast widget and am trying to add the forecast details to a widget (not mainwindow) using the following code and it turns out as in the image.

     int nrow=0,ncol=0;
    
                for(int i=0;i< wWind.length();i++){
                    QLabel *wind = new QLabel(wWind[i]);
                    QLabel *time = new QLabel(wDates[i]);
                    QString imagePath = ":/Images/weatherIcons/" + wIcons[i];
                    QImage weatherIcon(imagePath);
                    QLabel *iconLabel = new QLabel();
                    iconLabel->setPixmap(QPixmap::fromImage(weatherIcon.scaled(64,64,Qt::KeepAspectRatio,Qt::FastTransformation)));
                    iconLabel->setToolTip(wDescription[i]);
                    QVBoxLayout *wdatalay = new QVBoxLayout();
                    wdatalay->addWidget(iconLabel);
                    wdatalay->addWidget(wind);
                    wdatalay->addWidget(time);
                    ui->gridLayout_2->addLayout(wdatalay,nrow,ncol,0);
                    ncol++;
                    if(ncol==3)
                    {
                        ncol =0;
                        nrow++;
                    }
    
    
                }// for loop ends
    

    The problem I am facing is that some part of the icon and one of the label are getting truncated. How to avoid this? Is it is due to the problem due to some constraint in row and column size?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      addLayout(wdatalay,nrow,ncol,0); why are you setting rowspan to 0?

      You can set the minimum size explicitly iconLabel->setMinimumSize(QSize(64,64));

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • saitejS Offline
        saitejS Offline
        saitej
        wrote on last edited by
        #3

        Thats not the rowspan. It is the Alignment.

        The default rowspan and columnspan is 1

        1 Reply Last reply
        0
        • saitejS Offline
          saitejS Offline
          saitej
          wrote on last edited by
          #4

          The problem is the data is getting truncated as shown in the image. So if I want to display the data as it is by placing scrollbars, is it possible?

          VRoninV 1 Reply Last reply
          0
          • saitejS saitej

            The problem is the data is getting truncated as shown in the image. So if I want to display the data as it is by placing scrollbars, is it possible?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @saitej said in QGridlayout - problem while adding multiple layouts:

            So if I want to display the data as it is by placing scrollbars, is it possible?

            yes, just place your widget inside a scrollarea with setWidget()

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            saitejS 1 Reply Last reply
            1
            • VRoninV VRonin

              @saitej said in QGridlayout - problem while adding multiple layouts:

              So if I want to display the data as it is by placing scrollbars, is it possible?

              yes, just place your widget inside a scrollarea with setWidget()

              saitejS Offline
              saitejS Offline
              saitej
              wrote on last edited by saitej
              #6

              @VRonin said in QGridlayout - problem while adding multiple layouts:

              scrollarea with setWidget()

              But I have a layout (wdatalay) which I need to add and there is no addlayout in scrollarea.

              Is it possible to group all the 3 labels as a widget ?

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                ui->gridLayout_2 is probably set on a widget, you need to set that widget to be child of the scrollarea

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                saitejS 1 Reply Last reply
                1
                • VRoninV VRonin

                  ui->gridLayout_2 is probably set on a widget, you need to set that widget to be child of the scrollarea

                  saitejS Offline
                  saitejS Offline
                  saitej
                  wrote on last edited by
                  #8

                  @VRonin

                  Thanks !!

                  I have added these lines but there is no change.

                   QScrollArea *a = new QScrollArea(this);
                      a->setWidget(ui->dummy);
                      a->show();
                  

                  here, dummy is the widget ui->gridLayout_2 is set on

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    did you set the minimum size of the labels?

                    btw, this works for me, try and adapt this example with your images:

                    #include <QApplication>
                    #include <QScrollArea>
                    #include <QGridLayout>
                    #include <QLabel>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc,argv);
                        QScrollArea mainArea;
                        QWidget* dummyWid = new QWidget(&mainArea);
                        QGridLayout* mainLay = new QGridLayout(dummyWid);
                        for (int row = 0; row < 30; ++row){
                            for (int col = 0; col < 3; ++col) {
                                QLabel* tempLabel = new QLabel("Label " + QString::number(row) + ',' + QString::number(col), dummyWid);
                                mainLay->addWidget(tempLabel, row, col);
                            }
                        }
                        mainArea.setWidget(dummyWid);
                        mainArea.show();
                        return a.exec();
                    
                    }
                    

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    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