[SOLVED] Is QBoxLayout::addLayout broken?



  • I am trying to add a QVBoxLayout with some widgets inside of of a QHBoxLayout in the left and another widget in the right.

    But the widget inside of the main layout doesn't show where it is supposed to the right of the child vertical layout, instead it shows in the default top left position of the parent widget on top of the vertical layout.

    Adding another widget to the main horizontal layout doesn't add the widget to the side of the previous one but on top of it.

    @ main = new QHBoxLayout(this);
    table = new QTableView(this);
    main->addLayout(layout);
    main->addWidget(table);
    main->addWidget(new QPushButton("test", this));
    setLayout(main);@

    And the pretty result:
    !http://i46.tinypic.com/k213n.png(bug?)!

    Any ideas?



  • In line no 3 . where you are using addLayout(layout) , how is the layout instantiated eg:-

    @QVBoxLayout *layout = new QVBoxLayout(this); @

    if you are setting the parent as "this" for "layout" then that might be a problem as "main" layout is also instantiated with "this" as parent and later you are using setLayout(main).

    If that is the case then remove "this" from "layout" and try.

    Note:- You might be getting a warning : QLayout: Attempting to add QLayout "" to yourWidget "", which already has a layout



  • Ah yes, it worked by parenting to main->widget()

    It is strange thou, I expected ownership to be taken care of by addLayout() and move the ownership to the main layout.



  • [quote author="utcenter" date="1356008646"]
    It is strange thou, I expected ownership to be taken care of by addLayout() and move the ownership to the main layout.[/quote]

    Yeah even i have the same doubt regarding reparenting of layout. As widget get reparented , layouts should also work in the same way.



  • I myself find this strange, when content is added to a layout it does not take ownership itself but propagates the added object to the parent widget. For me it would make more sense for layouts to be parents of their content rather than the parent of the layout itself

    @Widget::
    QHBoxLayout::
    QVBoxLayout::
    QPushButton::
    QPushButton::
    QLineEdit::
    QLineControl::
    QProgressBar::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QLabel::
    QTableView::
    QWidget::qt_scrollarea_viewport
    QWidget::qt_scrollarea_hcontainer
    QScrollBar::
    QBoxLayout::
    QWidget::qt_scrollarea_vcontainer
    QScrollBar::
    QBoxLayout::
    QStyledItemDelegate::
    QHeaderView::
    QWidget::qt_scrollarea_viewport
    QWidget::qt_scrollarea_hcontainer
    QScrollBar::
    QBoxLayout::
    QWidget::qt_scrollarea_vcontainer
    QScrollBar::
    QBoxLayout::
    QHeaderView::
    QWidget::qt_scrollarea_viewport
    QWidget::qt_scrollarea_hcontainer
    QScrollBar::
    QBoxLayout::
    QWidget::qt_scrollarea_vcontainer
    QScrollBar::
    QBoxLayout::
    QTableCornerButton::@



  • Only a QWidget can be a parent of a QWidget. A QLayout as a non-visual, non-interactive item is not a QWidget.



  • So in my case QLayoutItem::widget() returns a 0, I didn't really bother to check it out once did the trick... still can save a runtime type check call


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.