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. After changing the contents directly in the setupUI function

After changing the contents directly in the setupUI function

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 754 Views
  • 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by IknowQT
    #1

    If I change the ui of the .ui file after directly changing the contents in the setupUI function, the contents that I coded by myself disappear.
    Is there a way to keep the hardcoded content as it is?

    setupUi(QWidget *wSpectrum_Setup)
    {
         scrollArea_Contents = new wSpectrum_Setup_Items(wSpectrum_Setup);
    }
    

    Existing wSpectrum_Setup_Items()
    After the change, wSpectrum_Setup_Items(wSpectrum_Setup);

    jsulmJ 1 Reply Last reply
    0
    • I IknowQT

      If I change the ui of the .ui file after directly changing the contents in the setupUI function, the contents that I coded by myself disappear.
      Is there a way to keep the hardcoded content as it is?

      setupUi(QWidget *wSpectrum_Setup)
      {
           scrollArea_Contents = new wSpectrum_Setup_Items(wSpectrum_Setup);
      }
      

      Existing wSpectrum_Setup_Items()
      After the change, wSpectrum_Setup_Items(wSpectrum_Setup);

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @IknowQT "After changing the contents directly in the setupUI function" - this is not a proper title.

      "after directly changing the contents in the setupUI function" - never change generated code - your changes will be gone next time code is generated!
      Why do you need to change generated code?!

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply
      2
      • jsulmJ jsulm

        @IknowQT "After changing the contents directly in the setupUI function" - this is not a proper title.

        "after directly changing the contents in the setupUI function" - never change generated code - your changes will be gone next time code is generated!
        Why do you need to change generated code?!

        I Offline
        I Offline
        IknowQT
        wrote on last edited by
        #3

        @jsulm

        I want to pass a pointer to wSpectrum_Setup.
        When initializing, we need the information in wSpectrum_Setup

        jsulmJ 1 Reply Last reply
        0
        • I IknowQT

          @jsulm

          I want to pass a pointer to wSpectrum_Setup.
          When initializing, we need the information in wSpectrum_Setup

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @IknowQT As I said: do not change generated code.
          You can change widgets in your forms after calling setupUi:

          ui->scrollArea_Contents = new wSpectrum_Setup_Items(wSpectrum_Setup);
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          I 2 Replies Last reply
          1
          • jsulmJ jsulm

            @IknowQT As I said: do not change generated code.
            You can change widgets in your forms after calling setupUi:

            ui->scrollArea_Contents = new wSpectrum_Setup_Items(wSpectrum_Setup);
            
            I Offline
            I Offline
            IknowQT
            wrote on last edited by
            #5

            @jsulm

            wSpectrum_Setup::wSpectrum_Setup(QWidget *parent)
            	: m_pScroller(new usrScrollBar(this))
            {
            	ui.setupUi(this);
            	this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
            
            	Initailize();
            }
            

            Are you saying Initalize should recreate it after calling setupui? If so, isn't it that two objects are created?

            Christian EhrlicherC 1 Reply Last reply
            0
            • I IknowQT

              @jsulm

              wSpectrum_Setup::wSpectrum_Setup(QWidget *parent)
              	: m_pScroller(new usrScrollBar(this))
              {
              	ui.setupUi(this);
              	this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
              
              	Initailize();
              }
              

              Are you saying Initalize should recreate it after calling setupui? If so, isn't it that two objects are created?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @IknowQT said in After changing the contents directly in the setupUI function:

              If so, isn't it that two objects are created?

              Yes, they are. Why do you want to replace it in code and not in designer -> promote widget

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              J.HilkJ 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @IknowQT said in After changing the contents directly in the setupUI function:

                If so, isn't it that two objects are created?

                Yes, they are. Why do you want to replace it in code and not in designer -> promote widget

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #7

                @Christian-Ehrlicher said in After changing the contents directly in the setupUI function:

                Yes, they are. Why do you want to replace it in code and not in designer -> promote widget

                because the OP's wSpectrum_Setup_Items object requieres a QWidget pointer in the constructor, AND it apparently has no default constructor and a secondary setter function for the mentioned widget


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                Christian EhrlicherC 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Christian-Ehrlicher said in After changing the contents directly in the setupUI function:

                  Yes, they are. Why do you want to replace it in code and not in designer -> promote widget

                  because the OP's wSpectrum_Setup_Items object requieres a QWidget pointer in the constructor, AND it apparently has no default constructor and a secondary setter function for the mentioned widget

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @J-Hilk Then the class should be changed instead adding all kind of hacks.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @IknowQT As I said: do not change generated code.
                    You can change widgets in your forms after calling setupUi:

                    ui->scrollArea_Contents = new wSpectrum_Setup_Items(wSpectrum_Setup);
                    
                    I Offline
                    I Offline
                    IknowQT
                    wrote on last edited by
                    #9

                    @jsulm

                    this->ui.scrollArea_Contents->setParent(this);
                    

                    You passed a pointer to the parent to setParent.
                    This is how I solved it.

                    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