PDA

View Full Version : QFrame inner rectangle



Micawber
1st April 2009, 19:39
Just a quick question that isn't entirely obvious to my addled brain...

When using a QFrame that has, lets say a StyledPanel shape. To get the coordinates and sizes of the rectangle within the frame, does one obtain it with calls to QFrame.window(), QFrame.width() and QFrame.height() etc.?

The Docs for QFrame state that a call to frameRect() will return the coordinates of the entire widget by default (with no frameRect set) but I don't think thats what I want and I'm not entirely sure how to get what I want.

Any illumination would be appreciated.

-Mic

talk2amulya
1st April 2009, 20:15
if you want inner rectangle's size, frameWidth() and frameHeight() is your answer

Micawber
1st April 2009, 20:24
I see frameWidth() but I don't see frameHeight(). Are you sure? :confused:

aamer4yu
1st April 2009, 21:00
frameHeight is not there. and it is obvious.

From the docs -

frameWidth : const int
This property holds the width of the frame that is drawn.

ie., it is something like the border width. subtract this from the frame rect, and you will get the inner rect :)

talk2amulya
1st April 2009, 21:02
oops, my bad..i assumed that height would be there :) plus on second thought..i think if u call contentsRect() on frame, u'd get right values that u want..also, to make sure u r doing right, call frameRect() and frameWidth()..frameRect() should be adjusted to framewidth on contentsRect().

talk2amulya
1st April 2009, 21:06
here is how frameRect() is calculated inside QFrame:


QRect QFrame::frameRect() const
{
Q_D(const QFrame);
QRect fr = contentsRect();
if ((d->oldFrameStyle & QFrame::Shape_Mask) == QFrame::StyledPanel) {
fr.adjust(-d->leftFrameWidth, -d->topFrameWidth, d->rightFrameWidth, d->bottomFrameWidth);
} else
fr.adjust(-d->frameWidth, -d->frameWidth, d->frameWidth, d->frameWidth);
return fr;
}

thus i believe contentsRect() should be what u need

Micawber
1st April 2009, 21:40
That makes sense. There a sentence on the QFrame documentation page that states...


The margin between the frame and the contents of the frame can be customized with the QWidget::setContentsMargins() function.

so the contentsRect() call should be what I need.

Thanks!

-Mic