br
19th November 2015, 12:14
Hi,
I am planning to add two widgets on my main widget in horizantal layout.
The width of left most widget (buttonsWindow) should be very small compared to width of right most widget (imageWindow).The purpose of left most widget is to show some buttons with some text , and purpose right most widget is to show some image based on button from left most widget.
I am using resize function to resize the widgets , but its not getting effected.
Somebody please show some pointers on how to change widgets size inside layouts.
#include "widget.h"
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QPushButton>
#include <QDesktopWidget>
#include<QRect>
#include <QApplication>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QRect rect;
rect = setScreenSize();
QWidget *buttonsWindow = new QWidget;
QWidget *imageWindow = new QWidget;
QHBoxLayout *hbox = new QHBoxLayout;
QVBoxLayout *vbox = new QVBoxLayout;
QPushButton *ltButton = new QPushButton(tr("<Button"));
QPushButton *NoC = new QPushButton(tr("&cdButton"));
// buttonsWindow->resize(rect.width()-800, rect.height()-100);
vbox->addWidget(ltButton);
vbox->addWidget(NoC);
buttonsWindow->setLayout(vbox);
QPalette Pal(palette());
// set black background
Pal.setColor(QPalette::Background, Qt::gray);
buttonsWindow->setAutoFillBackground(true);
buttonsWindow->setPalette(Pal);
// buttonsWindow->show();
hbox->addWidget(buttonsWindow);
//imageWindow->resize(rect.width()-200, rect.height()-200);
hbox->addWidget(imageWindow);
Pal.setColor(QPalette::Background, Qt::color1);
imageWindow->setAutoFillBackground(true);
imageWindow->setPalette(Pal);
setLayout(hbox);
}
Widget::~Widget()
{
}
QRect Widget:: setScreenSize()
{
QRect rec = QApplication::desktop()->screenGeometry();
resize(rec.width(), rec.height());
qDebug()<<"height="<<rec.height();
qDebug()<<"width="<<rec.width();
return rec;
}
I am planning to add two widgets on my main widget in horizantal layout.
The width of left most widget (buttonsWindow) should be very small compared to width of right most widget (imageWindow).The purpose of left most widget is to show some buttons with some text , and purpose right most widget is to show some image based on button from left most widget.
I am using resize function to resize the widgets , but its not getting effected.
Somebody please show some pointers on how to change widgets size inside layouts.
#include "widget.h"
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QPushButton>
#include <QDesktopWidget>
#include<QRect>
#include <QApplication>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QRect rect;
rect = setScreenSize();
QWidget *buttonsWindow = new QWidget;
QWidget *imageWindow = new QWidget;
QHBoxLayout *hbox = new QHBoxLayout;
QVBoxLayout *vbox = new QVBoxLayout;
QPushButton *ltButton = new QPushButton(tr("<Button"));
QPushButton *NoC = new QPushButton(tr("&cdButton"));
// buttonsWindow->resize(rect.width()-800, rect.height()-100);
vbox->addWidget(ltButton);
vbox->addWidget(NoC);
buttonsWindow->setLayout(vbox);
QPalette Pal(palette());
// set black background
Pal.setColor(QPalette::Background, Qt::gray);
buttonsWindow->setAutoFillBackground(true);
buttonsWindow->setPalette(Pal);
// buttonsWindow->show();
hbox->addWidget(buttonsWindow);
//imageWindow->resize(rect.width()-200, rect.height()-200);
hbox->addWidget(imageWindow);
Pal.setColor(QPalette::Background, Qt::color1);
imageWindow->setAutoFillBackground(true);
imageWindow->setPalette(Pal);
setLayout(hbox);
}
Widget::~Widget()
{
}
QRect Widget:: setScreenSize()
{
QRect rec = QApplication::desktop()->screenGeometry();
resize(rec.width(), rec.height());
qDebug()<<"height="<<rec.height();
qDebug()<<"width="<<rec.width();
return rec;
}