[Qt-interest] Best way to zoom an image
Mihail Naydenov
mlists at ymail.com
Fri Jan 21 09:03:24 CET 2011
You are doing it wrong :)
I meant to subclass an (QGraphics)Item not the view itself. QGraphicsView is a
framework, a canvas for Items (lightweight widgets).
As said study the samples and the docs. It will take (quite) some time if your
new to Qt/painting, but it is worth it.
MihailNaydenov
>
>From: "Cole, Derek" <dcole at integrity-apps.com>
>To: Mihail Naydenov <mlists at ymail.com>; qt-interest at qt.nokia.com
>Sent: Fri, January 21, 2011 1:18:57 AM
>Subject: RE: [Qt-interest] Best way to zoom an image
>
>RE: [Qt-interest] Best way to zoom an image
>
>Thanks for the tip. I did implement a QGraphicsView and I added a listener to it
>
>so that I can call the scale() function when the wheel moves forward or
>backwards.
>
>I do have one question regarding it through. I attached a MouseListener as I
>said, and I have it set to detect Mouse Wheel motions.
>
>if (event->type() == QEvent::Wheel) {
> QWheelEvent *wheelEvent = static_cast<QWheelEvent *>(event);
> if(wheelEvent->delta() > 0){
> //zoom in
> qDebug("Wheel Event");
> QString label = "graphicsView";
> QGraphicsView *l = this->parent()->findChild<QGraphicsView
>*>(label);
> if(l){
> qDebug("L not null");
> l->scale(.8,.8);
> }
> }else if(wheelEvent->delta() <= 0){....
>
>
>This seems to work partially, however, it only picks up the Wheel movements when
>
>I have scrolled all the way to the top or bottom edge of the image. Therefore,
>when I am zoomed all thew ay in, I have to scrole "up" forever before I hit the
>top edge of the image, and then it will start zooming out again. How can I make
>it so that it will never scroll the image with the wheel, it will just do my
>zoom action that I am catching here.
>
>Thanks
>
>Derek
>
>
>
>-----Original Message-----
>From: Mihail Naydenov [mailto:mlists at ymail.com]
>Sent: Thu 1/20/2011 2:50 PM
>To: Cole, Derek; qt-interest at qt.nokia.com
>Subject: Re: [Qt-interest] Best way to zoom an image
>
>To the "have I lost something with the compression to make the smaller image" -
>yes, you do, label has a scaled down version of p.
>To "is this this the best way to do it" - probably not for your scenario. You
>should drawPixmap() with scaled painter in some reimplementation of
>paintEvent/paint().
>I suggest either using QGraphicasView and reimpl an Item and draw in its paint.
>Or reimpl QWidget and draw in paintEvent if you dont need the whole graphics
>scene.
>I either case study both the samples and the demos provided with the sdk. There
>are may drawing related samples there.
>
>
>thumbs up
>MihailNaydenov
>
>
>>
>>From: "Cole, Derek" <dcole at integrity-apps.com>
>>To: "Cole, Derek" <dcole at integrity-apps.com>; qt-interest at qt.nokia.com
>>Sent: Thu, January 20, 2011 8:29:44 PM
>>Subject: Re: [Qt-interest] Best way to zoom an image
>>
>>RE: [Qt-interest] Best way to zoom an image
>>I also wanted to point out, that I used a label to display my image based on
>>something I read online as being the most common way.
>>
>>My end goal is to create sort of a canvas where I can zoom in on any part of
>the
>>image (under the mouse preferrably), track the location I am zoomed into
>>relative to the real image (in other words maybe now (0,0) of my label matches
>>up to (451,619) of my original image). I would also like to be able to draw a
>>rectangle over a portion of the scaled image, and then zoom in to that
portion,
>>again, tracking where I am in the zoomed image relative to the original.
>>
>>If all that isnt possible using my current configuration, please advise
>>
>>Thanks
>>
>>Derek
>>
>>-----Original Message-----
>>From: qt-interest-bounces+dcole=integrity-apps.com at qt.nokia.com on behalf of
>>Cole, Derek
>>Sent: Thu 1/20/2011 1:22 PM
>>To: qt-interest at qt.nokia.com
>>Subject: [Qt-interest] Best way to zoom an image
>>
>>
>>Hello,
>>
>>I have created a label that is containing a Pixmap of an image that is much
>>larger than the label, so I did some work to try to scale the image:
>>
>> QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
>> QPixmap p1(p.scaled(ui->viewLabel->width(),ui->viewLabel->height(),
>>Qt::KeepAspectRatio, Qt::SmoothTransformation ));
>> ui->viewLabel->setPixmap(p1);
>> ui->viewLabel->setFixedHeight(p1.height());
>> ui->viewLabel->setFixedWidth(p1.width());
>>
>>I guess my question is, if I wanted to get that pixmap p1 from the label, with
>>something like "viewLabel->pixmap()", can I now scale that image back to its
>>original size, or have I lost something with the compression to make the
>smaller
>>image when I first scaled p1?
>>
>>In other words, if I was to zoom "all the way in" on viewLabel's pixmap, would
>I
>>then be able to zoom all the way back out and see my full, unaltered image?
>>
>>If not, what is the best way to do this? I basically want to load my image,
and
>>then use the mouse wheel to zoom in and out on the image, always keeping the
>>same level of image quality
>>
>>Thanks
>>
>>Derek
>>
>>
>
>
>
>
>
More information about the Qt-interest-old
mailing list