Reputation: 49
How do I get the resolution from multiple widgets inside a layout.
For example I have the following:
ui.horizontalLayout_2->addWidget(&test1);
ui.horizontalLayout->addWidget(&test2);
ui.horizontalLayout->addWidget(&test3);
ui.horizontalLayout->addWidget(&test4);
Each of which is in a seperate window inside the layout.
I created this function not really understanding how to approach this problem which gives me the total resolution of the entire window.
void Widget::getScreenGeomerty()
{
QScreen* screen = QGuiApplication::primaryScreen();
QRect screenGeometry = screen->geometry();
int height = screenGeometry.height();
int width = screenGeometry.width();
qDebug() << "Screen height: " << height;
qDebug() << "Screen width: " << width;
}
What is the correct way to go about doing this.
#include "GLWidget.h"
class TestRecorder : public QMainWindow
{
Q_OBJECT
public:
TestRecorder( QWidget *parent = Q_NULLPTR);
~TestRecorder();
private:
Ui::TFMRecorderClass ui;
GLWidget test1;
GLWidget test2;
GLWidget test3;
GLWidget test4;
};
Upvotes: 1
Views: 54
Reputation: 597
All QWidget
-derived objects have height
and width
properties - Your test1, ... , test4
objects all are QWidget
-derived.
Simply reference their members, just like you did with screenGeometry
(also a QWidget
) e.g.
test1->height(); //Y Resolution
test1->width(); //x Resolution
Here you can find the documentation on height and width
EDIT:
To solve the issue of being unable to access height()
& width()
, forward declare the QGLWidget
class in your .h file. Such as:
#include "GLWidget.h"
class QGLWidget;
class TestRecorder : public QMainWindow
{
Q_OBJECT
// etc...
Upvotes: 1