PDA

View Full Version : Problem resizing a QFrame



rawfool
21st November 2011, 14:41
I've created a window and added a frame to it. The frame would contain some widgets such as LineEdit, ListBox, etc. I would change one frame with another one according to a menu selection. Now my issue is, when I maximize the main window, the frame is not getting expanded according to the new size. I tried to look at a few functions like sizePolicy, etc, but didn't understand though. I've provided the code below.

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QVBoxLayout>
#include <QFrame>

class MainWindow : public QMainWindow
{
Q_OBJECT

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

private:
QFrame *baseLayer;

};

#endif // MAINWINDOW_H


mainwindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
baseLayerSettings();
}

MainWindow::~MainWindow()
{

}
void MainWindow::baseLayerSettings(void)
{
baseLayer = new QFrame(this);
baseLayer->setGeometry(0, 0, 800, 600);
baseLayer->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
baseLayer->setStyleSheet("background-color: qlineargradient(spread:pad, x1:0.504, y1:1, x2:0.497273, y2:0, stop:0 rgba(51, 142, 220, 255), stop:1 rgba(255, 255, 255, 255))");

}


Please help me with this. Thank you.

norobro
21st November 2011, 16:55
. . . added a frame to it. . . . No, you haven't. Try this:
baseLayerSettings();
setCentralWidget(baseLayer);

rawfool
22nd November 2011, 04:53
Thank you dude. It worked.