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

QSqlTableModel ; how can I show my PNG data?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 874 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 6 Nov 2018, 15:41 last edited by
    #1

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

    J 1 Reply Last reply 6 Nov 2018, 16:06
    0
    • R RahibeMeryem
      6 Nov 2018, 15:41

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

      J Offline
      J Offline
      JonB
      wrote on 6 Nov 2018, 16:06 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 6 Nov 2018, 16:40 last edited by RahibeMeryem 11 Jun 2018, 16:40
        #3

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 6 Nov 2018, 16:43 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 6 Nov 2018, 16:45 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
            • D Offline
              D Offline
              dheerendra
              Qt Champions 2022
              wrote on 6 Nov 2018, 16:54 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 7 Nov 2018, 07:25 last edited by RahibeMeryem 11 Jul 2018, 07:32
                #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
                • V Offline
                  V Offline
                  VRonin
                  wrote on 7 Nov 2018, 08:48 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

                  6/8

                  6 Nov 2018, 16:54

                  • Login

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