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. Updating a Widget and repainting
Forum Updated to NodeBB v4.3 + New Features

Updating a Widget and repainting

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.7k 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.
  • S Offline
    S Offline
    Smeeth
    wrote on last edited by
    #1

    I am designing a UI made up of 3 components; a header panel across the top, a button panel down the right side, and a main content panel taking up the rest of the screen, like so:
    0_1532702477460_674df05c-1eae-47ed-a157-062c1e16d13f-image.png

    The Header and the Button Panel stay the same, but the content panel should switch between a couple different widgets. Is there a way to replace and repaint the widget on the screen without adding it to the layout again?

    This is the code I use to layout my widgets:

    mainLayout = new QGridLayout;
    mainLayout->setMargin(0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(headerPnl, 0, 0, 1, 7);
    mainLayout->addWidget(contentPnl, 1, 0, 10, 6);
    mainLayout->addWidget(buttonPnl, 1, 6, 10, 1);
    this->setLayout(mainLayout);
    

    This was my attempt to implement a setContentPnl method, but it doesn't seem to work. Nothing is replaced and the UI doesn't change.

    void MainWidget::setContentPnl(QWidget *content){
        contentPnl = content;
        contentPnl.repaint();
        contentPnl.update();
    }
    

    Is there a way I can point my contentPnl to different widgets, and update the screen accordingly?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      When you say " switch between a couple different widgets"
      you mean like flipping pages ?
      In that case, http://doc.qt.io/qt-5/qstackedwidget.html
      will make that easy.

      if you mean to actually replace the widget, you have to take it from layout and
      insert new one.

      Can you explain why u need to replace the widget ?
      is it sort of a preview of what is selected in Button panel or
      what does it do for app?

      S 1 Reply Last reply
      3
      • mrjjM mrjj

        Hi
        When you say " switch between a couple different widgets"
        you mean like flipping pages ?
        In that case, http://doc.qt.io/qt-5/qstackedwidget.html
        will make that easy.

        if you mean to actually replace the widget, you have to take it from layout and
        insert new one.

        Can you explain why u need to replace the widget ?
        is it sort of a preview of what is selected in Button panel or
        what does it do for app?

        S Offline
        S Offline
        Smeeth
        wrote on last edited by
        #3

        @mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.

        I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.

        mrjjM JonBJ 2 Replies Last reply
        0
        • S Smeeth

          @mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.

          I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Smeeth
          ok. make sure to use
          http://doc.qt.io/qt-5/qlayout.html#takeAt

          1 Reply Last reply
          0
          • S Smeeth

            @mrjj I mean to actually replace it. The app is meant to keep the header and button panel static, ie always there, always in the same place, and always looking the same. The only part of the screen that changes (as a result of different buttons being pressed) is the content panel.

            I suppose I will have to keep a reference to the layout and just remove and add when necessary. Thanks.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Smeeth
            But why not use a QStackedWidget for the Main Content Panel?

            1 Reply Last reply
            2

            • Login

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