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. Is there design mode for Qt Creator?
Forum Updated to NodeBB v4.3 + New Features

Is there design mode for Qt Creator?

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 4 Posters 5.8k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #14

    And the day you modify your parent object and the signal name changes, how many classes will you need to modify ?

    The signal emitter shouldn't care who is connected to it as well as the slot owner shouldn't care who emitted the signal. However, there's a need for an object somewhere to manage the connections and like I wrote before, using the parent argument in the child object is the wrong way to do it.

    You're thinking it simplifies the code a lot now, then you'll face maintenance nightmare later on. A good design doesn't mean the code will be simple, it means that the code will be easily understandable (as much as can be) and easy to maintain/update/improve.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    P 1 Reply Last reply
    1
    • SGaistS SGaist

      And the day you modify your parent object and the signal name changes, how many classes will you need to modify ?

      The signal emitter shouldn't care who is connected to it as well as the slot owner shouldn't care who emitted the signal. However, there's a need for an object somewhere to manage the connections and like I wrote before, using the parent argument in the child object is the wrong way to do it.

      You're thinking it simplifies the code a lot now, then you'll face maintenance nightmare later on. A good design doesn't mean the code will be simple, it means that the code will be easily understandable (as much as can be) and easy to maintain/update/improve.

      P Offline
      P Offline
      Panoss
      wrote on last edited by Panoss
      #15

      @SGaist said in Is there design mode for Qt Creator?:

      And the day you modify your parent object and the signal name changes, how many classes will you need to modify ?

      Two.

      @SGaist said in Is there design mode for Qt Creator?:

      The signal emitter shouldn't care who is connected to it as well as the slot owner shouldn't care who emitted the signal. However, there's a need for an object somewhere to manage the connections and like I wrote before, using the parent argument in the child object is the wrong way to do it.

      You're thinking it simplifies the code a lot now, then you'll face maintenance nightmare later on. A good design doesn't mean the code will be simple, it means that the code will be easily understandable (as much as can be) and easy to maintain/update/improve.

      Can you give me an example of how should I do it?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mtrch
        wrote on last edited by mtrch
        #16

        HACK: You can check applicationName and organizationName properties of application than uses widget.
        It will not work if somebody use custom Designer version with changed application/organization name. Also, it can be changed in future Designer versions.

        bool TestWidget::isDesignMode()
        {
            if((qApp->applicationName() == "Designer") &&
               ((qApp->organizationName() == "QtProject") || (qApp->organizationName() == "Trolltech")))
                return true;
            else
                return false;
        }
        
        P 1 Reply Last reply
        2
        • M mtrch

          HACK: You can check applicationName and organizationName properties of application than uses widget.
          It will not work if somebody use custom Designer version with changed application/organization name. Also, it can be changed in future Designer versions.

          bool TestWidget::isDesignMode()
          {
              if((qApp->applicationName() == "Designer") &&
                 ((qApp->organizationName() == "QtProject") || (qApp->organizationName() == "Trolltech")))
                  return true;
              else
                  return false;
          }
          
          P Offline
          P Offline
          Panoss
          wrote on last edited by Panoss
          #17

          @mtrch said in Is there design mode for Qt Creator?:

          HACK: You can check applicationName and organizationName properties of application than uses widget.
          It will not work if somebody use custom Designer version with changed application/organization name. Also, it can be changed in future Designer versions.

          bool TestWidget::isDesignMode()
          {
              if((qApp->applicationName() == "Designer") &&
                 ((qApp->organizationName() == "QtProject") || (qApp->organizationName() == "Trolltech")))
                  return true;
              else
                  return false;
          }
          

          I think this is very close to what I 'm looking for!!!
          But what is qApp? is it QtGui.QApplication?

          I tried this in the code that executes my class:

          if __name__ == "__main__":
          
              import sys
          
              qApp = QtGui.QApplication(sys.argv)    
              widget = PyPGDataTextBox(qApp.applicationName())
              widget.show()
              sys.exit(qApp.exec_())
          

          So my class inits with qApp.applicationName() as a parameter:

              def __init__(self, parent=None, appName=""):
                  super(PyPGDataTextBox, self).__init__(parent)
                  print("appName", appName, app)
                  self.setPlainText("appName=" + appName)
          

          But it prints nothing, appName is empty, either in design mode or in run mode.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Panoss
            wrote on last edited by
            #18

            In my init I put:

            appName=QtGui.qApp.applicationName()
            

            And when it runs in the design mode, returns 'Designer' while in run mode returns 'python'
            At last!! I found it!
            Thank you all for helping!

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #19
              if __name__ == "__main__"":
                  textBox = PyPGDataTextBox()
                  otherWidget = PyOtherWidget()
                  otherWidget.refreshsignal.connect(textBox.refresh)
              

              There, it's clean, understandable and easy to maintain. No need for workarounds or hacks for designer to work. PyPGDataTextBox doesn't need to know anything about PyOtherWidget.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Panoss
                wrote on last edited by Panoss
                #20

                I have some questions about this code.
                The value of name attribute is set to 'main' when module is run as main program.
                My widget, is never run as main program, so it's name attribute never gets a value of 'main'.
                Right?

                From my widget 's code, I removed totally the code at if name == "main": and the widget runs fine, in design and in run mode.

                So, maybe I don't need at all the 'if name == "main":' part?

                Edit: from what I understand, this code is in the module that gets executed.
                In my case, I have main.py, pgdatatextbox.pyw and pgdataform.pyw (a container (and parent) widget for data controls like pgdatatextbox).
                So this code is in my main.py, textbox is an instance of PyPGDataTextBox, and otherWidget is an instance of PyPGDataForm.
                And main connects these two with the signal.
                Do I get it right?

                If so, then when I add a new instance of PyPGDataTextBox, I 'll have to write code for it , in order to connect to the signal,in the main.

                With the 'QtGui.qApp.applicationName()', the new instance will connect (or not) by it's self, no extra code is needed anywhere.
                Isn't it better?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #21

                  That was just an example in the case you'd be creating your widget as part of your application start in main. Feel free to adapt that to whatever class constructor/function fits.

                  Like I said before, your child class assume that the parent is of a certain type that provides that signal, which by design is a bad idea.

                  You are now implementing a hack just to work around the fact that this expectation fails when using Designer which should also trigger an alarm.

                  Where exactly are you creating PyPGDataTextBox instances ?
                  What is your need of refreshsignal ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Panoss
                    wrote on last edited by Panoss
                    #22

                    @SGaist said in Is there design mode for Qt Creator?:

                    Where exactly are you creating PyPGDataTextBox instances ?
                    What is your need of refreshsignal ?

                    My PyPGDataTextBox instances are not created with code, they are created by Qt Designer.
                    When a PyPGDataTextBox recieves 'refreshsignal', it updates it 's text.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #23

                      Then put the connection code in the constructor of the widget where you put PyPGDataTextBox in.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1

                      • Login

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