PDA

View Full Version : Is Update() the right way?



td
5th December 2008, 14:41
Hi all,

I have a program in which two widgets are connected together. One widget displays an image and upon a mouse event (press) it passes the co-ordinates (in the form of a QPoint) to the other widget. My hope is that this Widget then displays a cropped version of the other image.

I have so far been unsuccessful in this. My main problem is updating the cropped-image display widget. Currently it shows nothing (the signals and slots are working by the way).

Here is the code


MyWidgetOne::MyWidgetOne(QWidget* parent): QWidget(parent)
{
int x, y;

coordOne = new QPoint;

drawLabel = new QLabel;
QPixmap dl;
dl.load("resources/image_ori.bmp");
dl = dl.copy(x-25, y-25, 50, 50);
dl.save("resources/image.bmp");
drawLabel->setPixmap(dl);


QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget(drawLabel);

setLayout(mainLayout);
setWindowTitle(tr("Receiver"));
}

void MyWidgetOne::showCoords(QPoint xy)
{
int i, j;
coordOne = &xy;
i = (coordOne->x());
j = coordOne->y();
x = i;
y = j;
update();
//repaint();
}

So as you can see I use x and y to define the corner of the area to be displayed (with a 50 height and width). When I receive the QPoint, I update this values via i and j).

I thought putting update() or repaint() would work but they have so far been of no use. Any help would be appreciated.

td
5th December 2008, 14:54
Hey,

Managed to get it working.


void MyWidgetOne::paintEvent(QPaintEvent *event)
{
QPixmap dm;
dm.load("resources/image_ori.bmp");
dm = dm.copy(x-25, y-25, 50, 50);
dm.save("resources/image.bmp");
drawLabel->setPixmap(dm);

}

Forgot to include the above :o I suppose just writing down the problem reminded me of what was missing!