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. What is required for children of QSplitter to be resized when the QSplitter changes size?
Forum Updated to NodeBB v4.3 + New Features

What is required for children of QSplitter to be resized when the QSplitter changes size?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 529 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.
  • O Offline
    O Offline
    olowo726
    wrote on last edited by
    #1

    Note that this isn't about what happens when the user moves the splitter position, this is about when the QSplitter widget is resized when the parent of the QSplitter changes layout.

    I have a dialog in which the layout of child widgets of a QSplitter needs special handling, i.e. standard layouts cannot be used. Hence I implemented according to headline "Manual Layout" on https://doc.qt.io/qt-5/layout.html for the children of the QSplitter. The result was that when the QSplitter is resized the children are not resized. When I remove the implementation for manual layout and use a box layout instead it works as intended when the QSplitter is resized.

    Hence, what must be fulfilled in order for the QSplitter to resize children when the QSplitter itself is resized?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      In your event method reimplementation you do not call the base class implementation for the events you do not handle, this is a bad idea.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        How exactly did you implement your manual layout ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • O Offline
          O Offline
          olowo726
          wrote on last edited by
          #3

          Header extract (dolayout is my own function)

          protected:
             bool event(QEvent *event) override;
             void resizeEvent(QResizeEvent *event) override;
             QSize	sizeHint() const override;
          private:
             void doLayout();
          

          Implementation

          bool YtScopeShelve::event(QEvent *event)
          {
             if (event->type() == QEvent::LayoutRequest)
             {
                doLayout();
                return true;
             }
             else
             {
                return false;
             }
          }
          
          void YtScopeShelve::resizeEvent(QResizeEvent *event)
          {
             QWidget::resizeEvent(event);
             doLayout();
          }
          
          QSize	YtScopeShelve::sizeHint() const
          {
             QWidget* yAxesWidget = findChild<QWidget*>("yAxesWidget");
             QWidget* plotAndTableWidget = findChild<QWidget*>("plotTableSplitter");
             // Height will be ignored by parent widgetlayout.
             return QSize(yAxesWidget->sizeHint().width() + plotAndTableWidget->sizeHint().width(), 100);
          }
          
          /*
           * According to https://doc.qt.io/qt-5/layout.html the child widgets shall be repositioned
           * on both QEvent::LayoutRequest and resizeEvent
           */
          void YtScopeShelve::doLayout()
          {
             QWidget* yAxesWidget = findChild<QWidget*>("yAxesWidget");
             QWidget* plotAndTableWidget = findChild<QWidget*>("plotTableSplitter");
             yAxesWidget->setGeometry(0, 0, yAxesWidget->sizeHint().width(), height());
             plotAndTableWidget->setGeometry(yAxesWidget->sizeHint().width(), 0, width() - yAxesWidget->sizeHint().width(), height());
          }
          

          resizeEvent is never called when parent of QSplitter resizes the QSplitter.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi,

            In your event method reimplementation you do not call the base class implementation for the events you do not handle, this is a bad idea.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • O Offline
              O Offline
              olowo726
              wrote on last edited by
              #5

              just detected that myself, thanks!

              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