Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWidget::geometry() vs. QWidget::frameGeometry()

Tags:

qt

qt4

Although Qt's docs indicate that these two functions are different (the first doesn't include the frame) no matter what widget I choose - including the main window of my application - someWidget->frameGeometry().height() always returns the same value as someWidget->geometry.height().

What am I missing here?

like image 520
planarian Avatar asked Jan 26 '13 18:01

planarian


3 Answers

I think, you don't give enough time to widget to be painted. There is little example:

#include <QApplication>
#include <QMainWindow>
#include <QDebug>

class MainWindow : public QMainWindow
{
public:
    MainWindow() {
        startTimer(500);
    }

    void timerEvent(QTimerEvent *e) {
        // Here values are different
        qDebug() << geometry().height() << frameGeometry().height();
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    MainWindow mainWin;
    mainWin.show();

    // Here values are equals
    qDebug() << mainWin.geometry().height() << mainWin.frameGeometry().height();

    return app.exec();
}

First debug output will produce the same values for geometry and frameGeometry, but the second (in timerEvent) will produce different.

like image 156
fasked Avatar answered Sep 27 '22 19:09

fasked


The QWidget class cannot have a frame. For example, QWidget doesn't have a frame, but QFrame has a frame.

like image 40
synacker Avatar answered Sep 27 '22 19:09

synacker


if QWidget is toplevel window then you can see borders and title bar around it. We call it frame or decoration frame and frameGeometry() returns exactly that: window size and position which includes OS decorations.On the other side geometry() returs QWidget inner rect which is available for other child controls or painting.See http://doc.qt.io/qt-4.8/application-windows.html#window-geometry for more details.Toplevel geometry() / frameGeometry() differs if our window is not frameless or fullscreen ... or we are talking about some frameless window manager under x11.

like image 20
Zeljan Rikalo Avatar answered Sep 27 '22 21:09

Zeljan Rikalo