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. QSpinbox delegate not added with QSqlQueryModel
Forum Updated to NodeBB v4.3 + New Features

QSpinbox delegate not added with QSqlQueryModel

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 4.0k Views 1 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.
  • raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    you haven't implemented the sizeHint() method of your delegate.

    Also you could use QAbstractItemView::sizeHintForColumn() to set the size for a specific column.

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hareen Laks
      wrote on last edited by
      #3

      @ raven-worx,

      Thanks for the reply.

      But my poor explanations directed you to the wrong path.

      I edited my post and now I think it says more things than before.

      Thanking you..

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #4

        do you mean "QAbstractItemView::openPersistentEditor()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#openPersistentEditor ?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hareen Laks
          wrote on last edited by
          #5

          No, I above image is just a sample image to show what I want.

          I detailed the requirement as points.

          1. I have item database. I query it using QSqlQueryModel and set that model to the QTableView. It is working fine and display the data according to the query. :)

          2. Then user should add the items to his cart by selecting how much he wants. To do that I need a 'Amount'Column with QSpinBox delegates as like as in above image. But I can not get that delegate. :(

          Can you help me?

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #6

            so you do want to edit the value of the field in your database?
            Or do you just want to display an additional column in the table for the amount (with no relation to the sql table data)

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hareen Laks
              wrote on last edited by
              #7

              latter one.

              I want to display the additional column as 'Amount' in the tableview. No relation to the table.

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #8

                well...that changes everything ;)

                You would make the view think there is an additional column. To do so you would need to implement a QProxyModel.
                To this QProxyModel you set your sql model. The QProxyModel gets set tot the view.
                Now basically you need to reimplement almost all virtual methods of the QProxyModel class and check if the passed model index points to your faked column (by checking the column index). If so return/call your desired values, else return/call the corresponding QProxyModel implementation.

                This is rather easy when you decide that your additional column should be the last column. If you decide to be anywhere in between other columns (like on the screenshot you've posted) you will have to map the index to the actual column index first before passing it tot he QProxyModel implementation.
                Another possibility instead of the index mapping would be to add it at the last position anyway and then just change the visual index of the column (see QHeaderView to do so), so the logical index stays the same.

                So i think thats enough work to do for now ;)

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  Hareen Laks
                  wrote on last edited by
                  #9

                  :(

                  It means I have to start from the beginning.

                  OK raven-worx. Now I begin to work in your path. First have to investigate what is QProxyModel.

                  Thank you very much!

                  When I got problems I'll contact you. ;)

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #10

                    no not from the beginning. All you have so far is more or less reusable :)
                    You are just missing the implementation to mimic the fake column.
                    So your sql model needs an "extension" with the QProxyModel.

                    But what i don't understand is:
                    In your delegate you are taken the value for the QSpinBox editor from your model, which is currently an sql model. But you said you want the column not a in relation to the sql table/model.

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hareen Laks
                      wrote on last edited by
                      #11

                      [quote author="raven-worx" date="1390294118"]
                      But what i don't understand is:
                      In your delegate you are taken the value for the QSpinBox editor from your model, which is currently an sql model. But you said you want the column not a in relation to the sql table/model.[/quote]

                      First I try to follow the tutorial which I mentioned in the beginning. So QStandardItemModel created. Then I try to change the model to QSqlQueryModel.

                      It happens because of that.

                      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