PDA

View Full Version : Displaying an image



seltra
2nd October 2010, 18:59
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


void MainWindow::showIt()
{
QLabel *image = new QLabel();
image->setPixmap( QPixmap( "car.jpg" ) );
image->show();
update();
}


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
showIt();
}

seltra
3rd October 2010, 10:14
Now i can change pixmap of Label with the code below

ui->label->setPixmap( QPixmap( "car.jpg" ) );

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.

Talei
3rd October 2010, 19:30
QLabel *label = new QLabel( "Push me" );
ui->[name of layout You want to place QLabel]->addWidget( label );