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. Need help from QT Experts ( Model / View for QDateTimeEdit widget)
Forum Updated to NodeBB v4.3 + New Features

Need help from QT Experts ( Model / View for QDateTimeEdit widget)

Scheduled Pinned Locked Moved Unsolved General and Desktop
model-viewqdatawidgetmappqdatetimeedit
27 Posts 5 Posters 5.6k 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.
  • C chakry
    14 Jun 2019, 09:57

    Yes i tried that but when the model data is changed then the signal is not fired , it never comes to this function . why is that ?

    QObject::connect(lView->selectionModel(), &QItemSelectionModel::currentChanged, this, [this](QModelIndex idx) -> void {
    	qDebug() << "modelchanged " << idx;
        }
    
    J Offline
    J Offline
    JonB
    wrote on 14 Jun 2019, 10:29 last edited by
    #21

    @chakry

    I need it because the model might change during run time

    Do you mean the whole model is changed, or just one item? If it's the former:
    https://doc.qt.io/qt-5/qitemselectionmodel.html#currentChanged

    Note that this signal will not be emitted when the item model is reset.

    and you might mean:
    https://doc.qt.io/qt-5/qitemselectionmodel.html#modelChanged

    This signal is emitted when the model is successfully set with setModel().

    or am I grasping the wrong end of the stick for what you are saying?

    C 1 Reply Last reply 14 Jun 2019, 11:05
    0
    • J JonB
      14 Jun 2019, 10:29

      @chakry

      I need it because the model might change during run time

      Do you mean the whole model is changed, or just one item? If it's the former:
      https://doc.qt.io/qt-5/qitemselectionmodel.html#currentChanged

      Note that this signal will not be emitted when the item model is reset.

      and you might mean:
      https://doc.qt.io/qt-5/qitemselectionmodel.html#modelChanged

      This signal is emitted when the model is successfully set with setModel().

      or am I grasping the wrong end of the stick for what you are saying?

      C Offline
      C Offline
      chakry
      wrote on 14 Jun 2019, 11:05 last edited by chakry
      #22

      @JonB Thank you .
      sorry i want to correct few things . Your code is working fine with view and set model i have just verified that. The reason it didnt work was i was not displaying my view.
      I must not show view to user . i just have to map the model to widget(QDateTimeEdit) and show that widget to user. I thought with view it might work if i dont show this to user. just set everything but not showing. This dont work right? please correct me.

      I meant both cases. in one case , one child value will be changed in another case a new model is set.I can connect these signals as you mentioned but they work with TreeView when visible right?

      V 1 Reply Last reply 14 Jun 2019, 12:47
      0
      • C chakry
        14 Jun 2019, 11:05

        @JonB Thank you .
        sorry i want to correct few things . Your code is working fine with view and set model i have just verified that. The reason it didnt work was i was not displaying my view.
        I must not show view to user . i just have to map the model to widget(QDateTimeEdit) and show that widget to user. I thought with view it might work if i dont show this to user. just set everything but not showing. This dont work right? please correct me.

        I meant both cases. in one case , one child value will be changed in another case a new model is set.I can connect these signals as you mentioned but they work with TreeView when visible right?

        V Offline
        V Offline
        VRonin
        wrote on 14 Jun 2019, 12:47 last edited by
        #23

        @chakry said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

        The reason it didnt work was i was not displaying my view.
        I must not show view to user . i just have to map the model to widget

        So how do you decide what parent item of the model should be edited in the widget?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        C 1 Reply Last reply 14 Jun 2019, 13:18
        0
        • V VRonin
          14 Jun 2019, 12:47

          @chakry said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

          The reason it didnt work was i was not displaying my view.
          I must not show view to user . i just have to map the model to widget

          So how do you decide what parent item of the model should be edited in the widget?

          C Offline
          C Offline
          chakry
          wrote on 14 Jun 2019, 13:18 last edited by
          #24

          @VRonin parent has a name , which is fixed. I will find it based on the name. The respective Model index is used unless a new model is updated.

          just a bit more explanation to be clear. I have a tree model and all these elements/children in tree model should be shown in view as a widget easily editable( ex: text box, checkbox, combobox, spinbox ..etc) . These standard items are working using widget mapper. I search for a parent and map its model index to one of the these standard widgets. In this model i also have 6 children's having date ,time info. I wanted to map these 6 children's to a single widget datetimeedit. This was my main issue . This is not possible with restriction on datawidgetmapper ( only one property can be mapped ).

          thanks and regards.

          V 1 Reply Last reply 14 Jun 2019, 14:06
          0
          • C chakry
            14 Jun 2019, 13:18

            @VRonin parent has a name , which is fixed. I will find it based on the name. The respective Model index is used unless a new model is updated.

            just a bit more explanation to be clear. I have a tree model and all these elements/children in tree model should be shown in view as a widget easily editable( ex: text box, checkbox, combobox, spinbox ..etc) . These standard items are working using widget mapper. I search for a parent and map its model index to one of the these standard widgets. In this model i also have 6 children's having date ,time info. I wanted to map these 6 children's to a single widget datetimeedit. This was my main issue . This is not possible with restriction on datawidgetmapper ( only one property can be mapped ).

            thanks and regards.

            V Offline
            V Offline
            VRonin
            wrote on 14 Jun 2019, 14:06 last edited by VRonin
            #25

            @chakry said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

            I wanted to map these 6 children's to a single widget datetimeedit. This was my main issue . This is not possible with restriction on datawidgetmapper ( only one property can be mapped ).

            This is what the code in my 2 connect do:
            This puts an index inside the QDatetimeEdit

            if(!idx.isValid())
                            return;
                        while(idx.parent().isValid())
                            idx =idx.parent();
                        lastIdx = QPersistentModelIndex();
                        editor->setDateTime(QDateTime(
                            QDate(
                                idx.model()->index(0,0,idx).data().toInt()
                                ,idx.model()->index(1,0,idx).data().toInt()
                                ,idx.model()->index(2,0,idx).data().toInt()
                            )
                            , QTime(
                                idx.model()->index(3,0,idx).data().toInt()
                                ,idx.model()->index(4,0,idx).data().toInt()
                                ,idx.model()->index(5,0,idx).data().toInt()
                            )
                        ));
                        lastIdx = idx;
            

            This puts the data from the QDatetimeEdit back into the model

            if(!lastIdx.isValid())
                            return;
                        model->setData(model->index(0,0,lastIdx),datetime.date().year());
                        model->setData(model->index(1,0,lastIdx),datetime.date().month());
                        model->setData(model->index(2,0,lastIdx),datetime.date().day());
                        model->setData(model->index(3,0,lastIdx),datetime.time().hour());
                        model->setData(model->index(4,0,lastIdx),datetime.time().minute());
                        model->setData(model->index(5,0,lastIdx),datetime.time().second());
                        model->setData(model->index(6,0,lastIdx),view->locale().toString(datetime.date(),QStringLiteral("dddd")));
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            C 1 Reply Last reply 17 Jun 2019, 12:45
            0
            • V VRonin
              14 Jun 2019, 14:06

              @chakry said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

              I wanted to map these 6 children's to a single widget datetimeedit. This was my main issue . This is not possible with restriction on datawidgetmapper ( only one property can be mapped ).

              This is what the code in my 2 connect do:
              This puts an index inside the QDatetimeEdit

              if(!idx.isValid())
                              return;
                          while(idx.parent().isValid())
                              idx =idx.parent();
                          lastIdx = QPersistentModelIndex();
                          editor->setDateTime(QDateTime(
                              QDate(
                                  idx.model()->index(0,0,idx).data().toInt()
                                  ,idx.model()->index(1,0,idx).data().toInt()
                                  ,idx.model()->index(2,0,idx).data().toInt()
                              )
                              , QTime(
                                  idx.model()->index(3,0,idx).data().toInt()
                                  ,idx.model()->index(4,0,idx).data().toInt()
                                  ,idx.model()->index(5,0,idx).data().toInt()
                              )
                          ));
                          lastIdx = idx;
              

              This puts the data from the QDatetimeEdit back into the model

              if(!lastIdx.isValid())
                              return;
                          model->setData(model->index(0,0,lastIdx),datetime.date().year());
                          model->setData(model->index(1,0,lastIdx),datetime.date().month());
                          model->setData(model->index(2,0,lastIdx),datetime.date().day());
                          model->setData(model->index(3,0,lastIdx),datetime.time().hour());
                          model->setData(model->index(4,0,lastIdx),datetime.time().minute());
                          model->setData(model->index(5,0,lastIdx),datetime.time().second());
                          model->setData(model->index(6,0,lastIdx),view->locale().toString(datetime.date(),QStringLiteral("dddd")));
              
              C Offline
              C Offline
              chakry
              wrote on 17 Jun 2019, 12:45 last edited by chakry
              #26

              @VRonin said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

              @chakry said in Need help from QT Experts ( Model / View for QDateTimeEdit widget):

              I wanted to map these 6 children's to a single widget datetimeedit. This was my main issue . This is not possible with restriction on datawidgetmapper ( only one property can be mapped ).

              Thank you VRonin for helping
              This is what the code in my 2 connect do:
              This puts an index inside the QDatetimeEdit ```
              ( Its true but where should i add this code , view and selectionmodel as you mentioned before doesnot work as there is no view in my case , any suggestion where to keep this )

              > ```cpp
              > if(!idx.isValid())
              >                 return;
              >             while(idx.parent().isValid())
              >                 idx =idx.parent();
              >             lastIdx = QPersistentModelIndex();
              >             editor->setDateTime(QDateTime(
              >                 QDate(
              >                     idx.model()->index(0,0,idx).data().toInt()
              >                     ,idx.model()->index(1,0,idx).data().toInt()
              >                     ,idx.model()->index(2,0,idx).data().toInt()
              >                 )
              >                 , QTime(
              >                     idx.model()->index(3,0,idx).data().toInt()
              >                     ,idx.model()->index(4,0,idx).data().toInt()
              >                     ,idx.model()->index(5,0,idx).data().toInt()
              >                 )
              >             ));
              >             lastIdx = idx;
              > ```
              > 
              > This puts the data from the `QDatetimeEdit` back into the model  ```
              **( This works as in this case i use dateTimechanged from QDateTimeEditsignal and set the passed model data)**
              
              if(!lastIdx.isValid())
                              return;
                          model->setData(model->index(0,0,lastIdx),datetime.date().year());
                          model->setData(model->index(1,0,lastIdx),datetime.date().month());
                          model->setData(model->index(2,0,lastIdx),datetime.date().day());
                          model->setData(model->index(3,0,lastIdx),datetime.time().hour());
                          model->setData(model->index(4,0,lastIdx),datetime.time().minute());
                          model->setData(model->index(5,0,lastIdx),datetime.time().second());
                          model->setData(model->index(6,0,lastIdx),view->locale().toString(datetime.date(),QStringLiteral("dddd")));
              
              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 17 Jun 2019, 13:07 last edited by VRonin
                #27

                Can you reformat the answer? it's difficult to follow...

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                0

                21/27

                14 Jun 2019, 10:29

                • Login

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