QSpinbox delegate not added with QSqlQueryModel
-
you haven't implemented the sizeHint() method of your delegate.
Also you could use QAbstractItemView::sizeHintForColumn() to set the size for a specific column.
-
@ 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..
-
do you mean "QAbstractItemView::openPersistentEditor()":http://qt-project.org/doc/qt-4.8/qabstractitemview.html#openPersistentEditor ?
-
No, I above image is just a sample image to show what I want.
I detailed the requirement as points.
-
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. :)
-
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?
-
-
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) -
latter one.
I want to display the additional column as 'Amount' in the tableview. No relation to the table.
-
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 ;)
-
:(
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. ;)
-
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. -
[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.