Hello wysota,
Thank you very much for the quick help.
So can I do my task just with a view or on MainWindow directly with "QPainter".
Can you please suggest me the right way for my task.
That is at least the road map.
Thanks in advance
ankireddy.n
Hello wysota,
Thank you very much for the quick help.
So can I do my task just with a view or on MainWindow directly with "QPainter".
Can you please suggest me the right way for my task.
That is at least the road map.
Thanks in advance
ankireddy.n
Yes. Well... you'll need some kind of widget of course besized the main window for the central widget.
The base is to render your pixmap in the paint event. If you want to draw something over it then do it after rendering the pixmap. Store everything you need for rendering in member variables of the class and use it in the paint event. So basically you do your logic in your custom methods (probably slots) and call update() to trigger a paint event that will redraw everything.Can you please suggest me the right way for my task.
Hello wysota,
Thanks a lot for the help.
With your help i made an example. I am drawing image in an Widget and mainwindow for slots.
Now I have a problem.
I am painting on the image. For this I implemented "mouseMoveEvent". Here I am changing the color of the image pixel at x, y location(getting from mouseMoveEvent) and calling update().
If the image size is small say 100X100 the things are OK. If the image size is more say 1828X778 then only a few points are setting color. All pixels along the mouse move path are not getting painted.
I observed this is because of calling "paintEvent" for every pixel. And paint event has the statement ( "QPixmap::fromImage(image) and painter.drawPixmap()") to display image.
This only for the cursor of size 1 pixel width. If the cursor size say 50 (50X50 rectangle in shape ) then it may not paint all pixels
I found two solutions for this problem
1) In paintEvent instead of calling "fromImage" method, just I am painting that x,y coordinate of the device with "painter.drawPoint()" method . But in this case as the pixmap has the old data and my drawing is not appear on the screen.
The code is as follows
mouseMoveEvent(QMouseEvent *event)
{
int x=mouseEvent->x();
int y=mouseEvent->y();
end.setX(x);
end.setY(y);
QRgb color=qRgb(255,0,0);
penColor=color;
image.setPixel(x,y,color);
getting=true;
updateImage=false;
update();
}
PaintEvent
QPainter paint(this);
if(readImage) //Do only after read image
{
if(updateImage)
{
pxmap=QPixmap::fromImage(image);
paint.drawPixmap(0,0,pxmap.width(),pxmap.height(), pxmap);
}
else
{
paint.setPen(penColor);
paint.drawPoint(end.x(),end.y());
paint.drawPixmap(0,0,pxmap.width(),pxmap.height(), pxmap);
}
}
2) After loading image, I scaled it to half of the image size and displaying the image for each and every pixel. In this case also if the image is zoom-in then again i am having the same problem
Another way is
A) pxmap=QPixmap::fromImage(image);
B) painter.drawPixmap(....);
D) QPainter painter(this);
E) then for every pixel update the pixel color only on device with out doing A and B steps. That is get QPainter painter(this) and painter.setPixel(x,y,color).
But I did not found any method like QPixmap::setPixel() which will update the device in such a way.
Can you please guide me how to solve this problem?
Thanks in advance
ankireddy.n
What is the purpose of this updateImage variable?
In general it should all be more or less like this:
Qt Code:To copy to clipboard, switch view to plain text mode
Hello wysota,
Thank you very much for your great help.
I did it.
Thanks
ankireddy.n
hi
i am new to Qt i want to display the uploaded image in the form2 .
i have created 2forms , where one form i have included all the fields like line edit , text edit etc and i have uploaded the image. the problem i am facing is i am unable to display the data of form 1 to form 2, and please help in displaying the image which is uploaded in form 1 to form 2.
u can find the attachements.
where regform is my main form(form1)
and message is my 2nd form(form 2)
Can you please guide me how to start Qt project which satisfies the above needs.
thankuregform.cppregform.hmessage.cppmessage.hmain.cpp
Bookmarks