[solved] How to get a real size of received and maximized window.
-
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? -
Hi,
What are you trying to achieve exactly with setWidgets ?
-
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();
}
@