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. QSqlTableModel ; how can I show my PNG data?

QSqlTableModel ; how can I show my PNG data?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 861 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
    RahibeMeryem
    wrote on last edited by
    #1

    How I can show the PNG data in the cell for QSqlTableModel ?

    JonBJ 1 Reply Last reply
    0
    • R RahibeMeryem

      How I can show the PNG data in the cell for QSqlTableModel ?

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

      @RahibeMeryem
      When you say "PNG data", do you mean you want to show the data as raw data bytes (0x... or whatever), or do you mean you want to show the actual picture?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RahibeMeryem
        wrote on last edited by RahibeMeryem
        #3

        @JonB PNG image.. sorry . actual picture ...

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          You can make it as QByteArray when you fetch from table. While showing you can construct the byte array as PixMap or QImage.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RahibeMeryem
            wrote on last edited by
            #5

            I can construct QPixmap from PNG / ByteArray,

            What I dont know is how to show in QSqlTableModel.

            I can show in normal table thats ok.

            I want to make a db-table browser for user to see data.

            Best

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              QSqlTableModel should be used with view to display. Use QTableView to display model contents. If you are using the TableView, custom delegate may be required display this image.

              If you are using the QTableWidget, you can QListWidgetItem and setIcon role.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              3
              • R Offline
                R Offline
                RahibeMeryem
                wrote on last edited by RahibeMeryem
                #7

                any example for siple delegate . ?

                 QSqlTableModel *model = new QSqlTableModel( nullptr, db_history);
                        model->setTable("persondb");
                        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
                        model->select();
                        model->setHeaderData(0, Qt::Horizontal, tr("id"));
                        model->setHeaderData(1, Qt::Horizontal, tr("name"));
                        model->setHeaderData(2, Qt::Horizontal, tr("date"));
                        model->setHeaderData(3, Qt::Horizontal, tr("PHOTO"));
                        model->setHeaderData(4, Qt::Horizontal, tr("location"));
                        model->setHeaderData(5, Qt::Horizontal, tr("category"));
                
                
                
                            ui->history_table->setModel(model);
                            ui->history_table->hideColumn(0); // don't show the ID
                            ui->history_table->show();
                

                This my table.

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  See https://forum.qt.io/post/411407

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved