Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:53:23+00:00 2026-06-02T19:53:23+00:00

I have some QDockWidget s (not floating, only closable) inside a single QWidget .

  • 0

I have some QDockWidgets (not floating, only closable) inside a single QWidget.
I have some widgets inside each QDockWidget – their heights should be equal.
These inner widgets can be hidden through the context menu.

My inner widgets should have equal height. I done it this way:

void MyDocksPanel::redistributeSpace()
{
    QBoxLayout * lay = (QBoxLayout *)layout();
    for (int i = 0; i < lay->count(); i++)
    {
        QWidget * dock = lay->itemAt(i)->widget();
        if (dock == NULL)
            continue;

        int size = 0;
        foreach(QWidget * subWidget, dock->findChildren<QWidget*>())
            size += subWidget->isVisible() ? 1 : 0;

        if (dock->isVisible() && (size == 0))
            dock->hide();
        lay->setStretch(i, size);
    }
}

All works fine until I add some const elements to each QDockWidget: some horizontal scrollbars and some Labels… Now my inner widgets have different sizes. But it is necessary for me to set their heights strongly equal.

QLayout lays out widget sizes on one level of a widget’s hierarchy. How can I make height-equal subwidgets?

3 subwidgets vs 2 subwidgets

First picture

My first strategy to set stretches 3 and 2:

enter image description here

But, when i have added scroll bars:

enter image description here

Heights of my 5 widgets are equals to 37,37,37,28,28 … and thats the problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:53:26+00:00Added an answer on June 2, 2026 at 7:53 pm

    You’re on the right track with the stretch factors, but think in terms of pixel values rather than small proportions. Try setting the stretch factor of each dock widget to this:

    dockWidgetStretch = numChildWidgets * childWidgetMinimumHeight + scrollBarHeight;
    

    where childWidgetMinimumHeight and scrollBarHeight are both expressed in pixels, and are both constants.

    EDIT: Here is a working example. You might have to experiment a bit to get it to work with your program, but this should be a good start.

    header.h

    #include <QtGui>
    
    class WidgetWith3Children : public QWidget
    {
    public:
        WidgetWith3Children()
        {
            QTextEdit *edit1 = new QTextEdit;
            QTextEdit *edit2 = new QTextEdit;
            QTextEdit *edit3 = new QTextEdit;
            QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal);
            QVBoxLayout *layout = new QVBoxLayout;
            layout->addWidget(edit1);
            layout->addWidget(edit2);
            layout->addWidget(edit3);
            layout->addWidget(scrollBar);
            setLayout(layout);
        }
    };
    
    class WidgetWith2Children : public QWidget
    {
    public:
        WidgetWith2Children()
        {
            QTextEdit *edit1 = new QTextEdit;
            QTextEdit *edit2 = new QTextEdit;
            QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal);
            QVBoxLayout *layout = new QVBoxLayout;
            layout->addWidget(edit1);
            layout->addWidget(edit2);
            layout->addWidget(scrollBar);
            setLayout(layout);
        }
    };
    
    class OuterWidget : public QWidget
    {
    public:
        OuterWidget()
        {
            QDockWidget *dockWidget1 = new QDockWidget;
            QDockWidget *dockWidget2 = new QDockWidget;
            dockWidget1->setWidget(new WidgetWith3Children);
            dockWidget2->setWidget(new WidgetWith2Children);
            QVBoxLayout *layout = new QVBoxLayout;
    
            // 71 is the height of the minimum size hint for QTextEdit
            // 30 is the height of a horizontal scrollbar (on my system)
            layout->addWidget(dockWidget1, 71 * 3 + 30);
            layout->addWidget(dockWidget2, 71 * 2 + 30);
    
            layout->setMargin(0);
            setLayout(layout);
        }
    };
    

    main.cpp

    #include <QtGui/QApplication>
    #include "header.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        OuterWidget w;
        w.show();
    
        return a.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that can convert a single color in a template image
I have some code in jQuery that iterate through children in div using each().
Have some validating problems which seem to appear only when using the Auth component.
Have some task with Infragistics UltraGrid requirement. Found Infragistics controls' list on their site,
I have some code (unfortunately not written by me, or else I would know
I have some files that are uuencoded, and I need to decode them, using
I have some files stored at amazon. all in private mode, and since I
I have some script in my default page that redirects users to language specific
I have some Java code which performs bitwise operations on a BitSet. I have
I have some interesting problem for an hour.. In my flex project, all width

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.