QTableView Sorting Image
-
I am using QTableView with QSqlTableModel.
- I my table user can store image. So how images(pixmap) are stored in DB and how to dispaly pixmap?
- I my case, User can give image name using sort key(some alias), using which column should be sorted. For e.g'
Case 1 : I have two rows say R1 and R2 with 1 column. R1 has text A and R2 has text B. So when user sort by clicking column A and B shoud be sorted in order. This case is working for us.
Case 2: R1 at 1column contains pixmap , Since pixmap can't be sorted , can we give some name to image lets say 'Z' . User sees the image but when sorted in ascending order, the order should be R2 then R1?
Case 3: can alias be given to any cell ? e.g
Data is in ascending order, sorting is enabled
R1 - A
R2 - B
R3 - C
now alias or sort key for R1 is Z so in this case table should show
R2 - B
R3- C
R1 - A (in ascending with sort key as Z)
If sort key is given for any cell then it should be participated in ascending or descending order.
Some or all cell can have sort key at any moment.
-
I am using QTableView with QSqlTableModel.
- I my table user can store image. So how images(pixmap) are stored in DB and how to dispaly pixmap?
- I my case, User can give image name using sort key(some alias), using which column should be sorted. For e.g'
Case 1 : I have two rows say R1 and R2 with 1 column. R1 has text A and R2 has text B. So when user sort by clicking column A and B shoud be sorted in order. This case is working for us.
Case 2: R1 at 1column contains pixmap , Since pixmap can't be sorted , can we give some name to image lets say 'Z' . User sees the image but when sorted in ascending order, the order should be R2 then R1?
Case 3: can alias be given to any cell ? e.g
Data is in ascending order, sorting is enabled
R1 - A
R2 - B
R3 - C
now alias or sort key for R1 is Z so in this case table should show
R2 - B
R3- C
R1 - A (in ascending with sort key as Z)
If sort key is given for any cell then it should be participated in ascending or descending order.
Some or all cell can have sort key at any moment.
@SandeepKg1
Hello and welcome.I cannot begin to answer all your questions. But basically
-
You will have to store the bytes composing your pixmap/image in the database as whatever blob (arbitrary binary) field it allows. I'm not sure, but converting your image to a
QByteArray
may allowQSqlTableModel
to map it to such a database "blob" field. The pixmap can be displayed by writing aQStyledItemDelegate
for the column it is shown in. -
Sorting should be done at the model side. You may want to interpose a
QSortFilterProxyModel
on top of theQSqlTableModel
before attaching theQTableView
to allow flexible sorting. It is entirely up to you (in the code you write, see bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const) how you ascribe "values" to your pixmap columns so that they sort as you desire.
-
@SandeepKg1
Hello and welcome.I cannot begin to answer all your questions. But basically
-
You will have to store the bytes composing your pixmap/image in the database as whatever blob (arbitrary binary) field it allows. I'm not sure, but converting your image to a
QByteArray
may allowQSqlTableModel
to map it to such a database "blob" field. The pixmap can be displayed by writing aQStyledItemDelegate
for the column it is shown in. -
Sorting should be done at the model side. You may want to interpose a
QSortFilterProxyModel
on top of theQSqlTableModel
before attaching theQTableView
to allow flexible sorting. It is entirely up to you (in the code you write, see bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const) how you ascribe "values" to your pixmap columns so that they sort as you desire.
@JonB Thank you for replying. Any idea on Image's alias which can be hidden or visible but should be part of sorting so that image will be in sorted position.
-
-
@JonB Thank you for replying. Any idea on Image's alias which can be hidden or visible but should be part of sorting so that image will be in sorted position.
@SandeepKg1
Like I said, I don't much understand what you are saying. For example:Case 1 : I have two rows say R1 and R2 with 1 column. R1 has text A and R2 has text B.
Case 2: R1 at 1column contains pixmapThese are contradictory. A given column ("1column") cannot have either text or pixmap. You may understand what you are saying/intending, I do not.
If you have a column which has a pixmap you have two ways of giving it some value to sort by:
- Like I wrote, do whatever you like for it in an override of QSortFilterProxyModel::lessThan().
- Use QSortFilterProxyModel::sortRole to assign a role other than
Qt::DisplayRole
to be used for sorting. UsesetData()
to assign a value for that role in rows/columns which includes desired value for the pixmap items.