Results 1 to 3 of 3

Thread: How to Load Image File into Desiger Created Qlabel?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    1

    Default How to Load Image File into Desiger Created Qlabel?

    Hello all,

    I'm in the process of learning c++ and read Thinking in c++, its lovely book. I ordered a book called C++ GUI Programming with Qt 4 (2nd Edition), but it wont arrive until next week. I use a mac and i wanted to develop a small program that would work on windows and mac and my professor recommended QT Framework for me. any way, please forgive me for my extremely newbie question: I have Created an interface in QT to load an image and display it in a Qlabel, and i was able to load the image in a label that pops up and not in the Qlabel that i already created in the designer view which already hold the same name:

    Qt Code:
    1. void MainWindow::on_btnLoadImage_clicked()
    2. {
    3.  
    4. QString fileName = QFileDialog::getOpenFileName(this,
    5. tr("Open File"), QDir::currentPath());
    6. if (!fileName.isEmpty()) {
    7. QImage image(fileName);
    8. if (image.isNull()) {
    9. QMessageBox::information(this, tr("Image Viewer"),
    10. tr("Cannot load %1.").arg(fileName));
    11. return;
    12. }
    13. imageLabel = new QLabel;
    14. imageLabel->setPixmap(QPixmap::fromImage(image));
    15. imageLabel->show();
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    I didn't get the idea of slots and signals and still understanding how to create a class and call its member functions, every book talks about apples, oranges, cars, wheels, engines, shapes, circles, squares and stuff like that and its still not making sense to me.

    please advice me on how to update different Qlabels -that i already put in the designer view- with images and text.

    thanks for the help in advance

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    17
    Thanked 90 Times in 88 Posts

    Default Re: How to Load Image File into Desiger Created Qlabel?

    Hi!

    How to access the 'designed' widgets depends on what you set up in the form-creation wizard (Advanced .. Multiple Inheritance, vs private member, ...)

    Probably its: ui->objectname. .. Where objectname is the name you provided in designer.

    Look at these free books:

    http://www.qtrac.eu/marksummerfield.html => http://www.qtrac.eu/C++-GUI-Programm...t-4-1st-ed.zip
    The DesignerIntegration in Creator makes the UI stuff easier, than this first edition describes.

    http://cartan.cas.suffolk.edu/oopdoc...rce/index.html

    Good fun with Qt! It's brilliant!

    Johannes

  3. The following user says thank you to JohannesMunk for this useful post:

    Not Fast Enough (14th April 2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanks
    1

    Default Re: How to Load Image File into Desiger Created Qlabel?

    Thanks Johannes , Your reply was extremely helpful.
    I used ui-> then i got the names of the objects in my designer view like that:

    Qt Code:
    1. ui->imageLabel->setPixmap(QPixmap::fromImage(image));
    To copy to clipboard, switch view to plain text mode 

    Regards,

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2009, 10:55
  2. Load an image in QLabel
    By zeeb100 in forum Qt Programming
    Replies: 9
    Last Post: 13th March 2009, 13:51
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. best way to load image from db
    By C167 in forum Qt Programming
    Replies: 2
    Last Post: 10th April 2008, 18:24
  5. changing QLabel font size(label created on the graphicsView)
    By maverick_pol in forum Qt Programming
    Replies: 11
    Last Post: 17th August 2007, 08:36

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.