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. can i set value at model without using SetModelData()
QtWS25 Last Chance

can i set value at model without using SetModelData()

Scheduled Pinned Locked Moved Unsolved General and Desktop
setmodeldataqstyleditemdele
4 Posts 3 Posters 604 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.
  • R Offline
    R Offline
    rahi444
    wrote on last edited by
    #1

    I'm creaing an ComboBox object In QStyledItemDelegate::createEditor().
    And Reading the model data and displaying into ComboBox in QStyledItemDelegate::setEditorData();

    I know if user changes any value at combobox, we will get those selected values in SetModelData() so that we can write into Model.

    But now my task is to write selected value to model witout using SetModelData();

    Can anyone guide me how to do this. My questions are.

    1. How do i get selected values without using SetModelData().
    2. How can set value to Model without using SetModelData(). i mean how can i know which Model & which index to use to SetData().
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You can use
      model->setData(index, "data", Qt::EditRole);

      its hard answer .2 as it really depends on where you mean ?

      1 Reply Last reply
      4
      • R Offline
        R Offline
        rahi444
        wrote on last edited by
        #3

        Thanks, but how do i get "data". I should take from User's selected checkbox.
        As i told you, in SetEditorData(), i'm reading model's data and displaying in ComboBox.

        As per my understanding, we can get user's selected data at SetModelData() only, but i don't have this option. In that case, do we have any other workaround to get selected data from combobox ?

        JonBJ 1 Reply Last reply
        0
        • R rahi444

          Thanks, but how do i get "data". I should take from User's selected checkbox.
          As i told you, in SetEditorData(), i'm reading model's data and displaying in ComboBox.

          As per my understanding, we can get user's selected data at SetModelData() only, but i don't have this option. In that case, do we have any other workaround to get selected data from combobox ?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @rahi444
          I don't claim to understand why you want to do this. However, does the example (teh accepted solution to it) in, say, https://stackoverflow.com/questions/36778577/qstyleditemdelegate-how-to-make-checkbox-button-to-change-its-state-on-click give you what you need? It's using https://doc.qt.io/qt-5/qstyleditemdelegate.html#editorEvent to access the widget's state in an event. Seems a bit low-level to me, but maybe that's what you do....?

          Otherwise, I know the editor arranges to store the widget's value via editor widget's user property, see https://doc.qt.io/qt-5/qstyleditemdelegate.html#setModelData itself. Can you leverage that without actually calling setModelData()?

          Finally, https://doc.qt.io/qt-5/qstyleditemdelegate.html#createEditor returns the widget created for doing the editing. Can you put your own slots/call functions on that to recognise when it's edited and retrieve its value directly?

          If all else fails, what about looking at the source of the setModelData() method you do not want to use in page https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qstyleditemdelegate.cpp.html ? You can see there what it does (looks pretty simple), and decide what you want to do compared to that, since you don't want to call it yourself for whatever reason.

          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