Results 1 to 4 of 4

Thread: QGraphicsLinearLayout does not behave like QVBoxLayout

  1. #1
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsLinearLayout does not behave like QVBoxLayout

    The left side(QGraphicsView,QGraphicsLinearLayout based)of the window should behave like the right side(QWidget,QVBoxLayout based) of the window.
    This means QTreeWidget and QPushBotton should fill the whole area of QGraphicsView. Also if the window is resized.

    Any ideas how to fix this code? Or is there a complete different way?

    Qt Code:
    1. GraphicWidgetTest::GraphicWidgetTest(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5.  
    6. // left side
    7. QGraphicsView *view = new QGraphicsView(ui.centralWidget);
    8. view->setScene(scene);
    9.  
    10. //scene->setBackgroundBrush(QBrush(QColor(Qt::red)));
    11. QGraphicsLinearLayout *vboxl = new QGraphicsLinearLayout;
    12. vboxl->setOrientation(Qt::Vertical);
    13. vboxl->addItem(scene->addWidget(new QTreeWidget));
    14. vboxl->addItem(scene->addWidget(new QPushButton("buttonl")));
    15.  
    16. QGraphicsWidget *form = new QGraphicsWidget;
    17. form->setLayout(vboxl);
    18. scene->addItem(form);
    19.  
    20. // right side
    21. QWidget *right = new QWidget(ui.centralWidget);
    22. QVBoxLayout *vboxr = new QVBoxLayout;
    23. vboxr->addWidget(new QTreeWidget);
    24. vboxr->addWidget(new QPushButton("buttonr"));
    25. right->setLayout(vboxr);
    26.  
    27. //
    28. QHBoxLayout *hbox = new QHBoxLayout;
    29. hbox->addWidget(view);
    30. hbox->addWidget(right);
    31.  
    32. ui.centralWidget->setLayout(hbox);
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 5th September 2009 at 11:52.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsLinearLayout does not behave like QVBoxLayout

    To do that you have to scale the scene according to the size of the view (i.e. in it's resizeEvent).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QGraphicsLinearLayout does not behave like QVBoxLayout

    You have to be cautious with QGraphicsLinearLayout.

    It's not called QGraphicsBoxLayout for a reason. It doesn't behave exactly the same.

  4. #4
    Join Date
    Feb 2007
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsLinearLayout does not behave like QVBoxLayout

    I have implemented the resizeEvent(). It works good if the size of the window is increased. But it does not decrease the size of QTreeWidget,QPushBotton if the windows size is decreased.
    Do i have to resize any other Widget?

    Qt Code:
    1. GraphicWidgetTest::GraphicWidgetTest(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. ui.setupUi(this);
    5.  
    6. // left side
    7. view = new QGraphicsView(ui.centralWidget);
    8. scene = new QGraphicsScene;
    9. view->setScene(scene);
    10.  
    11. scene->setBackgroundBrush(QBrush(QColor(Qt::red)));
    12.  
    13. left = new QGraphicsWidget();
    14. left->resize(view->size());
    15. QVBoxLayout *vboxw = new QVBoxLayout;
    16. Tree = new QTreeWidget;
    17. Button = new QPushButton("buttonl");
    18. QGraphicsProxyWidget *gTree = scene->addWidget(Tree);
    19. QGraphicsProxyWidget *gButton = scene->addWidget(Button);
    20. QGraphicsLinearLayout *vboxl = new QGraphicsLinearLayout;
    21. vboxl->setOrientation(Qt::Vertical);
    22. left->setLayout(vboxl);
    23. vboxw->addWidget(Tree);
    24. vboxw->addWidget(Button);
    25. scene->addItem(left);
    26. //vboxl->addItem(scene->addWidget(left));
    27. vboxl->addItem(gTree);
    28. vboxl->addItem(gButton);
    29.  
    30. //QGraphicsWidget *form = new QGraphicsWidget;
    31. //form->setLayout(vboxl);
    32. //scene->addItem(form);
    33.  
    34. // right side
    35. right = new QWidget(ui.centralWidget);
    36. QVBoxLayout *vboxr = new QVBoxLayout;
    37. vboxr->addWidget(new QTreeWidget);
    38. vboxr->addWidget(new QPushButton("buttonr"));
    39. right->setLayout(vboxr);
    40.  
    41. //
    42. QHBoxLayout *hbox = new QHBoxLayout;
    43. hbox->addWidget(view);
    44. hbox->addWidget(right);
    45.  
    46. ui.centralWidget->setLayout(hbox);
    47.  
    48. connect(Button,SIGNAL(clicked()),this,SLOT(buttonrClicked()));
    49. }
    50.  
    51. GraphicWidgetTest::~GraphicWidgetTest()
    52. {
    53. }
    54.  
    55. void GraphicWidgetTest::buttonrClicked()
    56. {
    57. left->resize(view->size().width()-3,view->size().height()-3);
    58. }
    59.  
    60. void GraphicWidgetTest::resizeEvent(QResizeEvent *event)
    61. {
    62. left->resize(view->size().width()-3,view->size().height()-3);
    63. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QVBoxLayout width size limit
    By QPlace in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 16:41
  2. Disable QVBoxLayout Border
    By Qt Coder in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2009, 12:50
  3. QVBoxLayout and QHBoxLayout problem
    By fmariusd in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2009, 20:58
  4. Inconsistent behaviour of QVBoxLayout
    By spraff in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2008, 18:36
  5. Custom Widget inside a QVboxLayout
    By nemesis in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2008, 14:55

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.