[Qt-interest] Drawing, Aspect Ratios, etc.
BRM
bm_witness at yahoo.com
Thu May 13 00:26:14 CEST 2010
I am working on some drawing functions in a custom widget that implements its own paintEvent().
My primary problem seems to be aspect ratio related.
The widget provides minimumSizeHint(), sizeHint(), and resizeEvent().
minimumSizeHint() and sizeHint() will return either a QSize(1000, 1000) or QSize(1280, 1024) depending on what is being drawn.
resizeEvent() enforces the aspect ratio as follows:
- gets the image size (either same as above) and creates a QSizeF with it.
- gets the event size's and increases the QSizeF to the event's size while maintaining the aspect ratio
- compares if they are the same
-- if not, calls resize with the new aspect ratio corrected size
-- if same, calls QWidget::resizeEvent(event)
Basically:
QSizeF aspectRatio(width, height);
QSizeF newSize(event->size());
aspectRatio.scale(newSize,Qt::KeepAspectRatio);
bool sameRatio = (newSize == aspectRatio);
if (sameRatio == false) {
resize(aspectRatio.toSize());
} else {
QWidget::resizeEvent(event);
}
The problem is that I am drawing a circle in my paintEvent() and it's not coming out as a circle:
qreal radius = 15;
QRectF aCircle;
aCircle.setHeight(radius);
aCircle.setWidth(radius);
aCircle.moveCenter(200,300);
painter.drawEllipse(aCircle);
When taking a screen shot, and clipping the boundary of the circle (a square around it - via MS Photo Editor), the Width x Height is 100x80, when it should be 100x100.
What am I doing wrong? What am I missing?
TIA,
Ben
More information about the Qt-interest-old
mailing list