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

Qt Code:
  1. #include <QtGui>
  2.  
  3. class LayoutItem : public QGraphicsWidget {
  4. public:
  5. LayoutItem(QGraphicsItem *parent = 0) : QGraphicsWidget( parent ) {}
  6. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  7. QWidget *widget = 0) {
  8.  
  9. qDebug() << "LayoutItem::paint, size = " << size();
  10. QRectF frame(QPointF(0,0), geometry().size());
  11. painter->drawRect( frame );
  12. }
  13.  
  14. };
  15.  
  16. class Window : public QGraphicsWidget {
  17. public:
  18. Window(QGraphicsWidget *parent = 0) {
  19.  
  20. QGraphicsGridLayout *grid = new QGraphicsGridLayout( this );
  21. LayoutItem* item = new LayoutItem;
  22. grid->addItem(item, 0, 0, 1, 1);
  23. item->resize( 400, 400 );
  24. }
  25. };
  26.  
  27. int main(int argc, char **argv)
  28. {
  29. QApplication app(argc, argv);
  30.  
  31.  
  32. Window *window = new Window;
  33. scene.addItem(window);
  34. QGraphicsView view(&scene);
  35. view.resize(500, 500);
  36. view.show();
  37.  
  38. return app.exec();
  39. }
To copy to clipboard, switch view to plain text mode