Qt-interest Archive, September 2007
how to keep the image ratio during dragging?
Message 1 in thread
ImageViewer developers,
I have a QScrollArea which holds a pixmap image.
After setWidgetResizable(true) the image fits the whole area.
My question is how to how to keep the image ratio during resize dragging?
There are three types of dragging: horizontal, vertical, and diagonal.
Is there a method to distinguish them, because I need to recalculate the
width, for example, if drag vertically.
Thanks in advance,
Lingfa
--
[ signature omitted ]
Message 2 in thread
Lingfa Yang wrote:
> ImageViewer developers,
>
> I have a QScrollArea which holds a pixmap image.
> After setWidgetResizable(true) the image fits the whole area.
> My question is how to how to keep the image ratio during resize dragging?
>
> There are three types of dragging: horizontal, vertical, and diagonal.
> Is there a method to distinguish them, because I need to recalculate
> the width, for example, if drag vertically.
>
> Thanks in advance,
> Lingfa
>
>
More details:
1) subclassing:
class ImageViewer1 : public QScrollArea
2) setWidget:
ImageViewer1::ImageViewer1()
{
imageLabel = new QLabel;
this->setWidget(imageLabel);
}
3) setPixmap:
this->imageLabel->setPixmap(pixmap);
4) setWidgetResizable:
this->setWidgetResizable(true);// fitToWindow
5) Catch event:
void ImageViewer1::resizeEvent ( QResizeEvent * event ) // [virtual
protected]
{
QSize oldSize = event->oldSize();
QSize size = event->size();
// change size ...
imageLabel->resize(size); // does not work ???
//QAbstractScrollArea::resizeEvent(event);
}
--
[ signature omitted ]