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. How to display multiple images on MainWindow??
Forum Updated to NodeBB v4.3 + New Features

How to display multiple images on MainWindow??

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 14.8k 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.
  • C Offline
    C Offline
    CognitiveRobot
    wrote on last edited by
    #5

    Lukas, thanks again. I couldn't figure it out using layout. But i managed another way. need to add picLabel->repaint() at the end of my mentioned code.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tesmai4
      wrote on last edited by
      #6

      I tried to follow your code snippet for displaying all images from a folder. I read all images in QList<QImage> list and then use foreach loop to display.
      This code only displays one image. A blank area is displayed for more than one iterations..........
      @
      QHBoxLayout *layout = new QHBoxLayout; // or any other layout
      ui->label_2->setLayout(layout);
      ...
      QPixmap myPic(QApplication::applicationDirPath()+"imageName" );
      QLabel *picLabel = new QLabel;
      QPixmap scaledPic(myPic.scaled(ui->label_2->width(),ui->label_2->height()));
      picLabel->setPixmap( scaledPic );
      layout->addWidget(picLabel);
      @
      Any help is appreciated.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #7

        Did you put the whole code into your loop, or just the lines after <code>QPixmap myPic(...</code>?

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

          Try this:
          @
          QVBoxLayout* PicsLayout=new QVBoxLayout(ui->label_2);
          ...
          //then inside the loop:
          QPixmap myPic(QApplication::applicationDirPath()+"imageName" ); //image1.png, image2.png,
          QLabel *picLabel = new QLabel(ui->label_2);
          picLabel->setScaledContents(true);
          picLabel->setPixmap(myPic);
          PicsLayout->addWidget(picLabel);
          @
          You should get all the images in a column.
          use QHBoxLayout instead of QVBoxLayout if you want them in a row or QGridLayout if you want them in a grid but, in this case, you should specify the number of column and row for each pic as additional arguments to addWidget

          "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
          • T Offline
            T Offline
            tesmai4
            wrote on last edited by
            #9

            thanks VRonin for reply.

            @QList<QImage> images;
            foreach(QFileInfo fileInfo, filesList)
            {
            tempFileName += fileInfo.fileName();
            QImage image(tempFileName);
            copy = image.scaled(inputWidth.toUInt(),inputHeight.toUInt(),Qt::KeepAspectRatio);
            images.append(image);
            }
            //loop correctly populates the list and "images" list has 9 images

            QHBoxLayout *verticalPicsLayout=new QHBoxLayout(ui->imageLabel2);
            for(int i=0;i<images.size();i++)
            {
            QPixmap p(QPixmap::fromImage(images[i]));
            QLabel *picLabel = new QLabel(ui->imageLabel2);
            picLabel->setScaledContents(true);
            picLabel->setPixmap(p);
            verticalPicsLayout->addWidget(picLabel);
            }@

            It only shows the first image in list and not all the images....
            Am I missing something or doing something incorrectly?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tesmai4
              wrote on last edited by
              #10

              Lukas, I posted the code in my recent post, please have a look at it. Any pointer for solving the problem.........
              [quote author="Lukas Geyer" date="1357645867"]Did you put the whole code into your loop, or just the lines after <code>QPixmap myPic(...</code>?[/quote]

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tesmai4
                wrote on last edited by
                #11

                Each image represents thumbnail of a video stream. Next step is to play the video stream by clicking on respective thumbnail.

                How will I implement click and play video after displaying the thumbnails from current implementation?

                Am I moving in right direction? if not, suggestions are welcome.

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

                  Did you lay out ui->imageLabel2?

                  I wrote this small test code and the items are shown correctly:

                  Test.h
                  @
                  #ifndef TESTQT_H
                  #define TESTQT_H
                  #include <QWidget>
                  class QLabel;
                  class TestQt : public QWidget
                  {
                  Q_OBJECT
                  public:
                  TestQt(QWidget parent = 0);
                  private:
                  QLabel
                  MainLabel;
                  };
                  #endif
                  @

                  Test.cpp
                  @
                  #include "testqt.h"
                  #include <QtGui>

                  TestQt::TestQt(QWidget parent)
                  : QWidget(parent)
                  {
                  setMinimumSize(100,100);
                  MainLabel=new QLabel(this);
                  QHBoxLayout
                  MainLayout=new QHBoxLayout(this);
                  MainLayout->addWidget(MainLabel);
                  QHBoxLayout* HorFramesLayout=new QHBoxLayout(MainLabel);
                  QList<QPixmap> PixList;
                  for (int i=1;i<=9;i++){
                  // Generate 9 20x20 pixmap filled with different colours
                  PixList.append(QPixmap(20,20));
                  PixList.last().fill(QColor(255i/9,125,125));
                  }
                  foreach(QPixmap pix, PixList){
                  // put the pixmaps one next to the other
                  QLabel
                  PixLabel=new QLabel(MainLabel);
                  PixLabel->setScaledContents(true);
                  PixLabel->setPixmap(pix);
                  HorFramesLayout->addWidget(PixLabel);
                  }
                  }
                  @

                  main.cpp
                  @
                  #include "testqt.h"
                  #include <QtGui/QApplication>
                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  TestQt w;
                  w.show();
                  return a.exec();
                  }
                  @

                  Hope this example helps

                  "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
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #13

                    ok, I think i spotted the problem.
                    @tempFileName += fileInfo.fileName();@
                    should become
                    @tempFileName = fileInfo.fileName();@

                    You are just concatenating the filenames and the QImage constructor just uses the first one

                    "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
                    • T Offline
                      T Offline
                      tesmai4
                      wrote on last edited by
                      #14

                      Thanks for the correction, it works.

                      [quote author="VRonin" date="1357663085"]ok, I think i spotted the problem.
                      @tempFileName += fileInfo.fileName();@
                      should become
                      @tempFileName = fileInfo.fileName();@

                      You are just concatenating the filenames and the QImage constructor just uses the first one[/quote]

                      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