Results 1 to 4 of 4

Thread: Regarding displaying image in grid.

  1. #1
    Join Date
    Jan 2009
    Posts
    13
    Qt products
    Qt4

    Arrow Regarding displaying image in grid.

    I am trying to display the images in the grid using the below code.
    I am able to get the first image.But second image won't come .

    Qt Code:
    1. QGridLayout *grid = new QGridLayout();
    2.  
    3. //grid->setColumnMinimumWidth(2,30);
    4. imageLabel = new QLabel;
    5. imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    6. imageLabel->setScaledContents(true);
    7. setCentralWidget(imageLabel);
    8. resize(100,100);
    9. QString NextImagepath = "c:\\Data\\Images\\Pictures\\error.bmp";
    10. QPixmap Nextimage(NextImagepath);
    11. imageLabel->setPixmap(Nextimage);
    12. grid->addWidget(imageLabel,0,0);
    13. grid->addWidget(imageLabel,0,1);
    To copy to clipboard, switch view to plain text mode 

    what is the reason behind this?Information on this would be helpful.
    Last edited by wysota; 20th February 2009 at 11:27. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Regarding displaying image in grid.

    You can't add the same widget two times to the layout. If you do that the widget will be removed from the first layout and put into the second one.

  3. #3
    Join Date
    Jan 2009
    Posts
    13
    Qt products
    Qt4

    Default Re: Regarding displaying image in grid.

    I tried using different widget.Again the same problem.
    What can be the problem...


    QGridLayout *grid = new QGridLayout();

    //grid->setColumnMinimumWidth(2,30);
    imageLabel = new QLabel;
    imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    imageLabel->setScaledContents(true);
    setCentralWidget(imageLabel);
    resize(50,50);
    QString NextImagepath = "c:\\Data\\Images\\Pictures\\error.bmp";
    QPixmap Nextimage(NextImagepath);
    imageLabel->setPixmap(Nextimage);
    grid->addWidget(imageLabel,0,0);



    ilabel2 = new QLabel;
    ilabel2->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    ilabel2->setScaledContents(true);
    setCentralWidget(imageLabel);
    resize(50, 50);
    QString NextImagepath1 = "c:\\Data\\Images\\Pictures\\b_prevtrack_on.pn g";
    QPixmap Nextimage1(NextImagepath1);
    ilabel2->setPixmap(Nextimage1);
    grid->addWidget(ilabel2,2,1);

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Regarding displaying image in grid.

    This time you are replacing one central widget with another so again you only see one widget and the other gets deleted (or hidden). Please stop guessing and look into the documentation of QGridLayout, there is an example there that shows how to add widgets to the layout.

Similar Threads

  1. problem in Displaying image on push button
    By durgarao in forum Qt Tools
    Replies: 4
    Last Post: 2nd January 2009, 10:27
  2. Displaying a portion of an image
    By tas in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2008, 03:09
  3. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  4. Replies: 3
    Last Post: 25th August 2007, 16:53
  5. displaying png image for a given area..
    By sar_van81 in forum Qt Programming
    Replies: 1
    Last Post: 17th January 2007, 13:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.