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. QTableView Sorting Image
Forum Updated to NodeBB v4.3 + New Features

QTableView Sorting Image

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 362 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.
  • S Offline
    S Offline
    SandeepKg1
    wrote on last edited by
    #1

    I am using QTableView with QSqlTableModel.

    1. I my table user can store image. So how images(pixmap) are stored in DB and how to dispaly pixmap?
    2. 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.
    JonBJ 1 Reply Last reply
    0
    • S SandeepKg1

      I am using QTableView with QSqlTableModel.

      1. I my table user can store image. So how images(pixmap) are stored in DB and how to dispaly pixmap?
      2. 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.
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SandeepKg1
      Hello and welcome.

      I cannot begin to answer all your questions. But basically

      1. 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 allow QSqlTableModel to map it to such a database "blob" field. The pixmap can be displayed by writing a QStyledItemDelegate for the column it is shown in.

      2. Sorting should be done at the model side. You may want to interpose a QSortFilterProxyModel on top of the QSqlTableModel before attaching the QTableView 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.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @SandeepKg1
        Hello and welcome.

        I cannot begin to answer all your questions. But basically

        1. 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 allow QSqlTableModel to map it to such a database "blob" field. The pixmap can be displayed by writing a QStyledItemDelegate for the column it is shown in.

        2. Sorting should be done at the model side. You may want to interpose a QSortFilterProxyModel on top of the QSqlTableModel before attaching the QTableView 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.

        S Offline
        S Offline
        SandeepKg1
        wrote on last edited by
        #3

        @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.

        JonBJ 1 Reply Last reply
        0
        • S SandeepKg1

          @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.

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

          @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 pixmap

          These 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. Use setData() to assign a value for that role in rows/columns which includes desired value for the pixmap items.
          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