PDA

View Full Version : QGridLayout issue



talk2amulya
26th February 2009, 17:12
Hi All,

i m facing a very weird problem here. I have created a custom widget derived from QAbstractButton. i m adding five of these widgets to a gridlayout as they should be added.but the none of the widgets show up. never faced such a problem with grid layout. here is the code:


#include "indiciacontainer.h"
#include "indicia.h"
#include <QGridLayout>
IndiciaContainer::IndiciaContainer(QWidget *parent)
: QWidget(parent)
{
resize(800, 500);
indiciaGroup = new QButtonGroup(this);
Indicia *indicia = new Indicia(this);
Indicia *indicia2 = new Indicia(this);
Indicia *indicia3 = new Indicia(this);
Indicia *indicia4 = new Indicia(this);
Indicia *indicia5 = new Indicia(this);

indiciaGroup->addButton(indicia);
indiciaGroup->addButton(indicia2);
indiciaGroup->addButton(indicia3);
indiciaGroup->addButton(indicia4);
indiciaGroup->addButton(indicia5);

indicia->setSvgPicture("d:\\browser.svg");
indicia2->setSvgPicture("d:\\spheres.svg");
indicia3->setSvgPicture("d:\\browser.svg");
indicia4->setSvgPicture("d:\\shapes.svg");
indicia5->setSvgPicture("d:\\bubbles.svg");

QGridLayout *grid = new QGridLayout(this);
grid->setSpacing(5);
grid->addWidget(indicia, 0, 0);
grid->addWidget(indicia2, 0, 1);
grid->addWidget(indicia3, 1, 0);
grid->addWidget(indicia4, 1, 1);
grid->addWidget(indicia5, 2, 0);

QRect rect = grid->cellRect(0,0);
int x = rect.x();
int y = rect.y();
this->setLayout(grid);
}

here is indicia.h :


class Indicia : public QAbstractButton
{
Q_OBJECT

public:
Indicia(QWidget *parent);
~Indicia();
void setText(QString imageLabel);
void setSvgPicture(QString path);

protected:
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *);
private:
Ui::IndiciaChoice ui;
QSvgWidget *_svgWidget;
};

any help is appreciated. i need a brisk solution to this

thanks you guys!

jpn
26th February 2009, 17:15
Hi, see Custom Widgets in Layouts.

talk2amulya
26th February 2009, 17:25
thanks a lot..qt centre is heaven!

giacomelli.fabio
2nd January 2010, 18:32
Hi

a question

I have a grid layout in a form ( ui manual designed ), with some items.

I have to add to it a QSqltableview so I designed a frame, to put into it a QSqltableview .

Frame has a horizontal layout working ( another item is into it )

Problem is that QSqltableview doesn't resize itself like I think it should do.

Thanks

Bye