Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] Qt QRect geometry negative position (Windows)
QtWS25 Last Chance

[solved] Qt QRect geometry negative position (Windows)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brcontainer
    wrote on last edited by
    #1

    bq. Solution:
    I solved using the function QMainWindow::move()

    Indeed the geometry is not negative,
    the problem is to set the x and y the setGeometry is not considering the window border nor bar tute as working directly with the centralWidget instead of the whole window.
    This causes the titleBar and go away from the left edge of the screen.

    I believe it should be some thing missing is configured in the UI file

    bq. Note: I only tested it on windows7

    Follow the simple example in QT:

    mainwindow.cpp

    @#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;
    }@


    mainwindow.ui

    @<ui version="4.0">
    <class>MainWindow</class>
    <widget class="QMainWindow" name="MainWindow" >
    <property name="geometry" >
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle" >
    <string>MainWindow</string>
    </property>
    <widget class="QMenuBar" name="menuBar" />
    <widget class="QToolBar" name="mainToolBar" />
    <widget class="QWidget" name="centralWidget" />
    <widget class="QStatusBar" name="statusBar" />
    </widget>
    <layoutDefault spacing="6" margin="11" />
    <pixmapfunction></pixmapfunction>
    <resources/>
    <connections/>
    </ui>@


    main.cpp

    @#include "mainwindow.h"
    #include <QApplication>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
    }@


    mainwindow.h

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H@


    untitled2.pro

    @QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = untitled2
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui@

    QT project: https://github.com/brcontainer/qt-helper

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      what do you actually want to achieve?!

      to get the height at least from the title bar you can try the following:
      @
      QStyle * style = mainWindow->style();
      QStyleOptionTitleBar so;
      so.titleBarFlags = Qt::Window;
      int titlebarHeight = style->pixelMetric(QStyle::PM_TitleBarHeight, &so, mainWindow);
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • B Offline
        B Offline
        brcontainer
        wrote on last edited by
        #3

        @raven-worx thanks, but also has the borders of the window.

        I solved using the function QMainWindow::move()

        Thanks.

        QT project: https://github.com/brcontainer/qt-helper

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved