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 radio buttons programmatically
Forum Updated to NodeBB v4.3 + New Features

updating radio buttons programmatically

Scheduled Pinned Locked Moved Solved General and Desktop
44 Posts 4 Posters 12.5k 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #17

    I'm still wading through this, but I did discover a necessary change in the Q_PROPERTY macro:

        Q_PROPERTY(QString ipSource READ ipSource WRITE SetIpSource NOTIFY ipSourceChanged USER true)
    

    It wouldn't compile with the GET/SET terms.

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #18

      SGaist: in your example above, where does the signal come from that connects to the slot setAddressType()?

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

        IIRC, you are using a QDataWidgetMapper for that editor ? Correct, then with that definition, when you call addMapping it will use that property to get and set the data from that widget in the same manner as it does for QLineEdit or QSpinBox.

        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
        • mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #20

          OK, I think I get this in principle. From an implementation standpoint, how/when should the edit dialog retrieve this information from the custom widget -- another signal/slot?

          Thanks...

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

            I'm not sure I'm following you here. Isn't that widget already using QDataWidgetMapper ?

            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
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by mzimmers
              #22

              Yes:

              in editdialog.cpp

              IpSourceWidget m_isw; // IpSourceWidget is my custom widget
              m_mapper->addMapping(&m_isw, TAG_IP_CONFIG_SRC);
              

              But don't I still have to use this to update the group box? Like this:

                  if (qs.toStdString() == IP_SOURCE_TXT[IP_SOURCE_DHCP])
                  {
                      ui->groupBoxIpAssignment->setChecked(IP_SOURCE_DHCP);
                  }
                  else
                  {
                      ui->groupBoxIpAssignment->setChecked(IP_SOURCE_STATIC);
                  }
              

              EDIT: OK, that wasn't right. I changed it to this:

               QButtonGroup *m_qbg;    // button group for IP source selection.
               ...
               if (qs.toStdString() == IP_SOURCE_TXT[IP_SOURCE_DHCP])
              {
                  m_qbg->button(IP_SOURCE_DHCP)->setChecked(true);
              }
              else
              {
                  m_qbg->button(IP_SOURCE_STATIC)->setChecked(true);
              }
              

              This at least gets the correct value displaying in the edit dialog. Still not sure I'm really doing this right, though.

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

                Don't forget to emit the corresponding notification signal if the address type has changed.

                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
                • mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #24

                  Not sure I understand. The code above is in a slot in my edit dialog. Elsewhere I have a connect:

                  IpSourceWidget *m_isw;
                  ...
                  QObject::connect(m_isw, &IpSourceWidget::ipSourceChanged, this, &EditDialog::updateIpSource);
                  

                  Is this the signal you're referring to?

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

                    I was thinking about where you are emitting ipSourceChanged.

                    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
                    • mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #26

                      Well, maybe that's part of the problem...I wasn't aware I needed to use that signal.

                      I'm still feeling my way through this. My IpSource widget doesn't contain any display items; it just handles the model updating. It communicates with the edit dialog through some shared variables:

                      IpSourceWidget::IpSourceWidget(QWidget *parent, DeviceModel *d, QModelIndex *qmi) :
                          QWidget(parent), m_d(d), m_qmi(qmi)
                      {
                      }
                      
                      IpSourceWidget::~IpSourceWidget()
                      {
                      }
                      
                      QString IpSourceWidget::ipSource() const
                      {
                          return QString::fromStdString(IP_SOURCE_TXT[m_ics]);
                      }
                      
                      void IpSourceWidget::setIpSource(const QString &source)
                      {
                          m_d->getModel()->setData(*m_qmi, source);
                      }
                      

                      I'm getting unexpected results, though. For example, after I press my "commit" button, the argument passed into setIpSource is set to "false." No idea where that's coming from.

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

                        Why does IpSourceWidget know about DeviceModel and the corresponding QModelIndex ?

                        The idea behind that widget is that you use it the same way as the QLineEdit you have in your editor widget.

                        For example in a widget like QLineEdit you have something like:

                        void MyWidget::setMyStringProperty(const QString &newValue)
                        {
                            if (newValue == currentValue) {
                                return;
                            }
                        
                            currentValue = newValue;
                            // Do stuff if needed
                            emit myStringPropertyValueChanged(newValue);
                        }
                        

                        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
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #28

                          None of my other widgets require me to do anything other than calls to addMapping(). That's partly why this is so new to me.

                          In your example, is currentValue a member variable (or a persistent local), or am I obtaining it from the model? I originally thought the latter, but now I'm thinking I got it wrong.

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

                            Most of the time, it's a member variable.

                            In the case of your widget, it could be something like:

                            void IpSourceWidget::setIpSource(const QString& ipSource)
                            {
                                if ((ipSource == IP_SOURCE_DHCP && ui->dhcpButton->isChecked()) ||
                                     ipSource == IP_SOURCE_STATIC && ui->staticButton->isChecked())) {
                                    return;
                                }
                            
                               if (ipSource == IP_SOURCE_DHCP) {
                                    ui->dhcpButton->setChecked(true);
                               } else {
                                    ui->staticButton->setChecked(true);
                               }
                               emit ipSourceChanged(ipSource);
                            }
                            

                            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
                            • mzimmersM Offline
                              mzimmersM Offline
                              mzimmers
                              wrote on last edited by mzimmers
                              #30

                              That all makes sense, but who consumes the signal? You've already updated the ui, so the dialog doesn't need it (that I can see).

                              Thanks...

                              EDIT: oh, and continuing with this design, I guess the ipSource widget would merely return the member variable?

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

                                In this case, QDataWidget mapper will use it. Because you also have to implement the handling of that signal when you click on either of the radio button.

                                As for the getter:

                                QString IpSourceWidget::ipSource() const
                                {
                                    QString sourceType = "Unkown";
                                    if (ui->dhcpButton->isChecked() {
                                        sourceType = IP_SOURCE_DHCP ;
                                    } else {
                                        sourceType = IP_SOURCE_STATIC;
                                    }
                                    return sourceType;
                                }
                                

                                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
                                • mzimmersM Offline
                                  mzimmersM Offline
                                  mzimmers
                                  wrote on last edited by
                                  #32

                                  OK, this is starting to come together. Now...as I mentioned above, currently none of the display widgets (radio button or group box) reside in my custom widget. Is this a problem, or is there some way for me to access the widgets in the dialog ui (perhaps passing the ui variable in the c'tor)?

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

                                    The group box and buttons should be moved out of your original editor widget and into IpSourceWidget.

                                    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
                                    • mzimmersM Offline
                                      mzimmersM Offline
                                      mzimmers
                                      wrote on last edited by
                                      #34

                                      That's how I tried it originally, but then they insisted in showing up in separate windows. Can you point me to the right document to read to get them into the edit widget?

                                      Thanks...

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

                                        I could have wrote it clearer. Remove them from your original editor and either use designer to create the IpSourceWidget UI or do it by code.

                                        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
                                        • mzimmersM Offline
                                          mzimmersM Offline
                                          mzimmers
                                          wrote on last edited by
                                          #36

                                          OK, this is (yet another) first for me...I assume/hope that it's possible to superimpose my IpSourceWidget onto my EditDialog widget? (If I'm using the write terms)

                                          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