Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Is QBoxLayout::addLayout broken?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Is QBoxLayout::addLayout broken?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • U Offline
        U Offline
        utcenter
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          [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.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            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::@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • U Offline
                U Offline
                utcenter
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved