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. only some of the widgets are resizing properly

only some of the widgets are resizing properly

Scheduled Pinned Locked Moved General and Desktop
resizewidgets
1 Posts 1 Posters 611 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.
  • Y Offline
    Y Offline
    Yi Gin
    wrote on last edited by Yi Gin
    #1

    Hi all,
    I have created a custom widget, A, which I assign as the central widget.
    In its constructor I create and assign to it two other custom widgets - B and C.
    in A's constructor I put B and C inside a QVBoxLayout and add this layout to widget A.

    When I run the application and resize the window the B widget resizes properly but the C widget does not.
    I am attaching the redacted .h files and constructors of all these widgets.

    Any help will be appreciated.

    A.h:

    class A : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit A(QWidget *parent = 0);
        ~A();
        virtual int heightForWidth ( int w ) const { return w*535/1645;}
    
    private:
        Ui::A *ui;
        B* header_widget;
        C* body_widget;
        QVBoxLayout* main_layout;
        void setMainLayout();
    };
    

    A.cpp:

    A::A(QWidget *parent) : QWidget(parent), ui(new Ui::A)
    {
        ui->setupUi(this);
        setMainLayout();
        this->setLayout(main_layout);
    }
    
    A::~A()
    {
        delete ui;
    }
    
    
    void A::setMainLayout(){
        main_layout = new QVBoxLayout();
    
        header_widget = new B(this);
        body_widget = new C(this);
    
        main_layout->addWidget(B);
        main_layout->addWidget(C);
    }
    

    B.h:

    class B : public QWidget
    {
        Q_OBJECT
    
    public:
        explicit B(QWidget *parent = 0);
        ~B();
        virtual int heightForWidth ( int w ) const { return w*535/1645;}
    
    
    private:
        Ui::B *ui;
    };
    

    C.h:

    class C : public QStackedWidget
    {
        Q_OBJECT
    
    public:
        explicit C(QWidget *parent = 0);
        ~C();  
        virtual int heightForWidth ( int w ) const { return w*535/1645;}
    
    private:
        Ui::C *ui;
        A *widgetParent;
    };
    
    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