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?

Is there design mode for Qt Creator?

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 4 Posters 5.3k 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.
  • P Panoss

    Yes it's almost identical in python, I tried this too, but the function createWidget() gets called in both cases:
    when in design mode and
    when in run mode
    So the parameter designMode is always true!

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

    @Panoss
    Hi
    Oh ok.
    Im not sure what will be easiest way of detecting Design mode.
    Some use process id , some check if Designer interface can be initialized.

    And you are sure that the error from
    def init(self, parent=None):
    parent.refreshsignal.connect(self.refresh)

    is not coming from parent being NULL ( ehh None in python?)?

    def init(self, parent=None):
    if ( parent )
    parent.refreshsignal.connect(self.refresh)

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

      I tried this:

                  if parent is not None:
                      parent.refreshsignal.connect(self.refresh)
      

      And gives me the same error.
      So, parent is not None (not null)but the error still exists.
      It only goes away if I remove the connect command.

      mrjjM 1 Reply Last reply
      0
      • P Panoss

        I tried this:

                    if parent is not None:
                        parent.refreshsignal.connect(self.refresh)
        

        And gives me the same error.
        So, parent is not None (not null)but the error still exists.
        It only goes away if I remove the connect command.

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

        @Panoss
        Ok so not that.
        What does parent.refreshsignal.connect do ?
        ( not seen same in c++)

        It seems strange it could prevent the factory from working.

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

          Just one thing: your use of parent is a design error.

          You are creating a tight coupling here and it's a bad idea. If the there's a need for a connection between a parent signal and a child slot, it's the responsibility of the parent object to create it. The child shouldn't know nor care about what its parent is or does.

          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
          • mrjjM mrjj

            @Panoss
            Ok so not that.
            What does parent.refreshsignal.connect do ?
            ( not seen same in c++)

            It seems strange it could prevent the factory from working.

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

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

            What does parent.refreshsignal.connect do ?

            Parent sends a signal named 'refreshsignal'.
            To no one specific. Doesn't know who receives it and doesn't care.

            But the ones who receive it, are those ones who have been 'connected' to this signal named 'refreshsignal'.

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

            Just one thing: your use of parent is a design error.

            You are creating a tight coupling here and it's a bad idea. If the there's a need for a connection between a parent signal and a child slot, it's the responsibility of the parent object to create it. The child shouldn't know nor care about what its parent is or does.

            But the parent doesn't know who are the receivers of the signal, and this simplifies the code A LOT!!
            I thought that's the point of the signals.
            I 'm new in python so maybe you 're right, I don't know.

            1 Reply Last reply
            0
            • 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