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

  • Home
  • SEARCH
  • 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 214763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:24:20+00:00 2026-05-11T18:24:20+00:00

I would like to have a QMainWindow that can change it’s look at runtime,

  • 0

I would like to have a QMainWindow that can change it’s look at runtime, i.e when a user clicks a button. Besides keeping references to different UI classes generated by the QtDesigner, is there another way of doing that? Maybe by storing each UI in a layout ? What do you think ?

  • 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-05-11T18:24:21+00:00Added an answer on May 11, 2026 at 6:24 pm

    I think I got it now.

    You have a QMainWindow and when a certain event is triggered you want to change the appearance of that particular window, like remove some buttons, add a treeview widget or what not.

    Well the straight forward approach would be to do it manually, remove some widgets and add new ones using regular C++ code. This can be abit hard if you’re used to Qt Designer.

    The other way I can think of is using Qt Designer to generate the code for the other appearances and copy it to a special function. The code generated by Qt Designer is usually in a header file called “ui_classname.h” and isn’t hard to understand. You will however need to remove some of it as not all would be necessary.

    Also, instead of copying the generated code from Qt Designer you could just call it. Usually your widget has a pointer to the generated class and in your widget’s constructor you see something like this:

    MyWindow::MyWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MyWindow)
    {
        m_ui->setupUi(this);
    }
    

    and in the corresponding header file:

    class MyWindow : public QMainWindow {
    ...
    private:
        Ui::MyWindow *m_ui;
    };
    

    You could add the additional generated classes for the other appearances and use them when your event triggers.

    It might look like this:

    class MyWindow : public QMainWindow {
    ...
    private:
        void changeAppearance(int id);
    
        Ui::MyWindow *m_ui;
        Ui::MyWindowFirstAppearance *m_uiFirst;
        Ui::MyWindowSecondAppearance *m_uiSecond;
    ...
    };
    
    void MyWindow::changeAppearance(int id)
    {
         // some code to remove the current appearance, basically the opposite of what setupUi is doing
         if (id == 0)
               m_ui->setupUi(this);
         else...
               m_uiFirst->setupUi(this);
         ...
    }
    

    This has the benefit of using the generated classes directly, so every change you do in Qt Designer doesn’t require a change to your main window. The problem is I’m not sure if it’s legal to call setupUi more than once and in a place other than your widget’s constructor, so you’ll have to check that (by looking at what’s happening in the setupUi function).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I would like to have a QMainWindow that can change it's look at runtime,
I have a program that (amongst other things) has a command line interface that
I'm not sure if I'm entirely clear on the implications of attaching to events
Preface : I am new to the iPhone SDK, Obj-C, Interface Builder and Cocoa.
I was confused when I first started to see anti-singleton commentary. I have used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.