How to resize a layout item?
Hi,
I am trying to force a specific size on a layout item as shown (400x400), but it doesn't work. Is there a way for it?
Thanks
Code:
#include <QtGui>
class LayoutItem : public QGraphicsWidget {
public:
LayoutItem
(QGraphicsItem *parent
= 0) : QGraphicsWidget
( parent
) {}
qDebug() << "LayoutItem::paint, size = " << size();
painter->drawRect( frame );
}
};
class Window : public QGraphicsWidget {
public:
Window(QGraphicsWidget *parent = 0) {
QGraphicsGridLayout *grid = new QGraphicsGridLayout( this );
LayoutItem* item = new LayoutItem;
grid->addItem(item, 0, 0, 1, 1);
item->resize( 400, 400 );
}
};
int main(int argc, char **argv)
{
Window *window = new Window;
scene.addItem(window);
view.resize(500, 500);
view.show();
return app.exec();
}
Re: How to resize a layout item?
try resizing the item before you add it to the layout
Re: How to resize a layout item?
Quote:
Originally Posted by
talk2amulya
try resizing the item before you add it to the layout
It doesn't work either...
Re: How to resize a layout item?
Hi,
you have to use option->rect and implement the pure virtual function boundingRect()!
Code:
class LayoutItem : public QGraphicsWidget {
public:
LayoutItem
(QGraphicsItem *parent
= 0) : QGraphicsWidget
( parent
) {}
qDebug() << "LayoutItem::paint, size = " << option->rect;
painter->drawRect( option->rect );
}
{
return QRectF(0,
0,
400.0,
400.0);
}
};
class Window : public QGraphicsWidget {
public:
Window(QGraphicsWidget *parent = 0)
{
QGraphicsGridLayout *grid = new QGraphicsGridLayout( this );
LayoutItem* item = new LayoutItem;
grid->addItem(item, 0, 0, 1, 1);
}
};