tags:

views:

50

answers:

2

Hi.,

i am trying to create layout like this (Please see the Picture)

http://i225.photobucket.com/albums/dd200/saravanan_comp2001/layout.jpg

In the QT i created widgets and put in the main widget, the problem is not visible. none of the widget's are not shown. please help me to fix this issue

Complete Source Code sandbox.ifuturemec.com/test.zip

Source code mainWindow.cpp

#include "mainwindow.h"
#include <QtGui>
#include "headerbar.h"
#include <QGridLayout>
#include <QPushButton>
#include <QBoxLayout>
#include "statusbar.h"
#include "leftpanel.h"
#include "rightpanel.h"
#include "centerpanel.h"

mainWindow::mainWindow(QWidget *parent) : QWidget(parent)
{
   QGridLayout *layout=new QGridLayout(this);

    headerBar *Header= new headerBar(this);
    leftPanel *LeftPanel=new leftPanel(this);
    centerPanel *CenterPanel=new centerPanel(this);
    rightPanel *RightPanel=new rightPanel(this);
    statusBar *Status=new statusBar(this);

    QHBoxLayout *box=new QHBoxLayout();
    box->addWidget(LeftPanel);
    box->addWidget(CenterPanel);
    box->addWidget(RightPanel);

    layout->addWidget(Header,0,0);
    layout->addLayout(box,1,0);
    layout->addWidget(Status,2,0);

    setLayout(layout);
}

mainWindow::~mainWindow() {}

mainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>

class mainWindow : public QWidget
{
    Q_OBJECT
public:
    mainWindow(QWidget *parent = 0);
    ~mainWindow();

signals:

public slots:

};

#endif // MAINWINDOW_H

headerbar.cpp

#include "headerbar.h"
#include <QPushButton>
#include <QMessageBox>

headerBar::headerBar(QWidget *parent) : QWidget(parent)
{
    this->setMaximumHeight(24);
    this->setStyleSheet("background-color: rgb(85, 170, 255)");
}

headerBar::~headerBar(){}

headerbar.h

#ifndef HEADERBAR_H
#define HEADERBAR_H

#include <QWidget>

class headerBar : public QWidget
{
    Q_OBJECT
public:
    headerBar(QWidget *parent = 0);
    ~headerBar();

signals:

public slots:

};

#endif // HEADERBAR_H

Please help me to fix this problem.

+2  A: 

Actually, your widgets do show ! But they are empty and have nothing to show !

Regarding the background color you are setting : the background-color property is not showing, because this property is not supported by QWidget.

Have a look at the documentation regarding this : List of stylable widgets.

More specifically :

QWidget : Supports only the background, background-clip and background-origin properties.

If you try to put, for instance, a label in your widgets, you'll see they do show :

centerPanel::centerPanel(QWidget *parent) :
    QWidget(parent)
{
    QHBoxLayout *box = new QHBoxLayout(this);
    QLabel* pLabel = new QLabel("Center panel", this);
    box->addWidget(pLabel);
    this->setStyleSheet("background-color: rgb(85, 100, 100)");
}

alt text

Jérôme
Thanks. it's working. but i need to fix this the layout, with out widget also should display in full screen. Please give some suggestion.
saravanan
A: 

If you just want the mainWindow to have a solid background color, you might try to just forget using the stylesheet and override the paintEvent method like this:

void mainWindow::paintEvent(QPaintEvent *event)
{
setPalette(QPalette(QColor(85, 170, 255)));
setAutoFillBackground(true); 
}
teukkam
i need to put image as background to the widget. i don't want the solid color. i am new to QT. please give some suggestion. i need to create the image in runtime and put that image as background.
saravanan
`QFrame` might be what you are looking for, at least it supports the background-image property: http://doc.trolltech.com/4.6/stylesheet-examples.html#customizing-qframe
teukkam