Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] how to work with Geom in QT?



  • geom does not work right. When you define a new position for the window, part of it is off screen. How to solve this problem?

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QRect test(0,0,300,240);
    setGeometry(test);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    Solved:
    I was testing various functions QMainWindow and found the move()

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QRect test(0,0,300,240);
    setGeometry(test);
    move(0,0);//Fix
    

    }@



  • See the documentation for QWidget. See functions frameGeometry(), x(), y(), pos().



  • Could you give me an example? Thanks


  • Moderators



  • The documentation explains why the frameGeometry is different than the geometry. Basically it is because of the frame that is put around the widget by the operating systems window manager. Different window managers use different size frames. It is not possible to know the frameGeometry until after the window has been displayed.

    The best practice is to set the size of the widget with resize() and let the window manager set the location of it.



  • Solved:

    I found the answer to this problem.

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QRect test(0,0,300,240);
    setGeometry(test);
    move(0,0);//Fix
    

    }@


Log in to reply