Results 1 to 3 of 3

Thread: Displaying an image

  1. #1
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Displaying an image

    i want to display a car photo.
    after loading, user can move the car by pressing keys on keyboard.
    when he press "up arrow", car will move upwards.
    which methos should i use to show the photo. Qlabel.setpixmap??
    The code below shows the image on a new widget, but i want to show it on my mainwindow page.
    What should i do?
    Thank you

    Qt Code:
    1. void MainWindow::showIt()
    2. {
    3. QLabel *image = new QLabel();
    4. image->setPixmap( QPixmap( "car.jpg" ) );
    5. image->show();
    6. update();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. showIt();
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Displaying an image

    Now i can change pixmap of Label with the code below
    Qt Code:
    1. ui->label->setPixmap( QPixmap( "car.jpg" ) );
    To copy to clipboard, switch view to plain text mode 

    but for this code i need to create a QLabel in forms window.
    So i can manipulate it's Pixmap property.

    But how can i create a Label in centralwidget after the run of the program?
    thank you.

  3. #3
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Displaying an image

    Qt Code:
    1. QLabel *label = new QLabel( "Push me" );
    2. ui->[name of layout You want to place QLabel]->addWidget( label );
    To copy to clipboard, switch view to plain text mode 
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. as displaying an image in a mdi?
    By Lycus HackerEmo in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2010, 12:14
  2. Displaying image
    By Rui in forum Newbie
    Replies: 1
    Last Post: 20th June 2009, 21:15
  3. Regarding displaying image in grid.
    By prajna in forum Newbie
    Replies: 3
    Last Post: 20th February 2009, 19:39
  4. Displaying a portion of an image
    By tas in forum Qt Programming
    Replies: 4
    Last Post: 28th November 2008, 03:09
  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.