PDA

View Full Version : Problem with adding picture during running



d@nyal
2nd May 2010, 20:01
Hi everybody,

I have a function which draws a picture on screen :

void MainWindow::darwAGate(int x,int y,int gate_code)
{
//load images:
QPixmap *pixmap_and = new QPixmap("../pix/AND.png");

QHBoxLayout *h_layout = new QHBoxLayout();
QLabel *label_tmp = new QLabel(this);
label_tmp->setGeometry(x,y,gate_width_pixel,gate_height_pixel );
label_tmp->setPixmap(*pixmap_and);
h_layout->addWidget( label_tmp );
this->setLayout(h_layout);
}


I have to draw some pix in start of the program, so I like this:

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

//draw pics
darwAGate(100, 100, 3);
}

The on screen i see the pixs. So i dont have any problem till here.

In the ui I have a bottum which I want to use that for inserting additional pix on screen:


void MainWindow::on_pushButton_clicked()
{
// a sample pic :
darwAGate(100, 100, 2);
}

Unfortunately I don't see any additional pic on screen, when I click on push_bottun.

Whats wrong?


Thanks in advance!

Lykurg
2nd May 2010, 20:20
first, is the slot called? second, with setLayout in your draw function, you delete every earlier set layout. So this not not the right way to go!

d@nyal
3rd May 2010, 03:55
first, is the slot called?

You mean I click on the bottun? (Yes!)


second, with setLayout in your draw function, you delete every earlier set layout. So this not not the right way to go!

Do mean that I can't paint several pics with this function,by deleting previous layout ?
How do you think I'd better to do ?

Thanks.

Lykurg
3rd May 2010, 07:43
You mean I click on the bottun? (Yes!)No, I hope you are able to click a button;) I meant have you checked if the slot is really called. E.g. Put a qWarning() statement in the slot and see if at runtime the message appears or use a debugger to check.

Do mean that I can't paint several pics with this function,by deleting previous layout ?
How do you think I'd better to do ?

Thanks.

You can, but setGeometry and using a layout is nonsense, since one "overwrites" the other. So in your case you probably want to use only setGeometry. Also you can store the positions in a local member variable and do all the painting in the paint event of your widget.