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] How to get a real size of received and maximized window.
Forum Updated to NodeBB v4.3 + New Features

[solved] How to get a real size of received and maximized window.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    never_ever
    wrote on last edited by
    #1

    Hi,
    I have a method that get pointer to widget where should be setted some other widgets. I have to resize the main window, where that widget is placed and then I should get the real size of that widget.

    I've tried to do this like:

    @
    void MyClass::setWidgets(QList<QWidget*> list, QWidget parentWidget)
    {
    QWidget
    mainWindow = parentWidget->window();
    mainWindow->showMaximized();

    int width = parentWidget->size().width();
    int height = parentWidget->size().height();
    /*... rest of method...*/
    

    }
    @

    That method is call from other class.
    But I read that I should wait for resizeEvent. Could anyone explain me how I should do this or if there is any option to get that size differently?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are you trying to achieve exactly with setWidgets ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        never_ever
        wrote on last edited by
        #3

        I wanted to add QWidgets to the window. I managed that problem with some help from other forum. Writing resizing filter was enough.

        This is what I found ("link here - code also below":http://stackoverflow.com/questions/24203215/qt-how-to-get-real-size-of-maximized-window-that-i-have-pointer-to/24205602#24205602

        bq.
        If you want to get events for a different object, you can install an event filter using QObject::installEventFilter.
        bq.
        A simple example for ResizeEvent is:

        filter.h

        @
        #ifndef FILTER_HPP
        #define FILTER_HPP

        #include <QtGui>

        class ResizeFilter : public QObject
        {
        Q_OBJECT
        public:
        ResizeFilter();
        protected:
        bool eventFilter(QObject *obj, QEvent *event);
        };

        #endif
        @

        filter.cpp

        @
        #include "filter.h"

        ResizeFilter::ResizeFilter() : QObject() {}

        bool ResizeFilter::eventFilter(QObject obj, QEvent event)
        {
        if (event->type() == QEvent::Resize)
        {
        QResizeEvent
        resizeEv = static_cast<QResizeEvent
        >(event);
        qDebug() << resizeEv->size();
        }
        return QObject::eventFilter(obj, event);
        }
        @

        main.cpp

        @
        #include <QtGui>
        #include "filter.hpp"

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

        ResizeFilter filter;

        QWidget window;
        window.installEventFilter(&filter);
        window.showMaximized();

        return app.exec();
        }
        @

        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