Results 1 to 4 of 4

Thread: How to resize a layout item?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

    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 

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resize a layout item?

    try resizing the item before you add it to the layout

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to resize a layout item?

    Quote Originally Posted by talk2amulya View Post
    try resizing the item before you add it to the layout
    It doesn't work either...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to resize a layout item?

    Hi,

    you have to use option->rect and implement the pure virtual function boundingRect()!

    Qt Code:
    1. class LayoutItem : public QGraphicsWidget {
    2. public:
    3. LayoutItem(QGraphicsItem *parent = 0) : QGraphicsWidget( parent ) {}
    4. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    5. QWidget *widget = 0) {
    6.  
    7. qDebug() << "LayoutItem::paint, size = " << option->rect;
    8. painter->drawRect( option->rect );
    9. }
    10. QRectF boundingRect() const
    11. {
    12. return QRectF(0,0,400.0,400.0);
    13. }
    14.  
    15. };
    16.  
    17. class Window : public QGraphicsWidget {
    18. public:
    19. Window(QGraphicsWidget *parent = 0)
    20. {
    21. QGraphicsGridLayout *grid = new QGraphicsGridLayout( this );
    22. LayoutItem* item = new LayoutItem;
    23. grid->addItem(item, 0, 0, 1, 1);
    24. }
    25. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Resize widget force layout resizing
    By ^NyAw^ in forum Qt Programming
    Replies: 17
    Last Post: 11th February 2009, 11:27
  2. Resize button when using layout
    By Macok in forum Qt Tools
    Replies: 3
    Last Post: 26th January 2009, 00:31
  3. Move and resize with layout
    By waediowa in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2008, 08:16
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. Replies: 3
    Last Post: 4th April 2008, 19:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.