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 to show png images in table
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel, how to show png images in table

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 574 Views 1 Watching
  • 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 RahibeMeryem
    #1

    Hi,

    I have :

              QSqlTableModel *model = new QSqlTableModel ();
                model->setEditStrategy(QSqlTableModel::OnFieldChange);
                model->setTable("personel");
                model->setEditStrategy(QSqlTableModel::OnManualSubmit);
                model->select();
                model->setHeaderData(0, Qt::Horizontal, tr("name"));
                model->setHeaderData(1, Qt::Horizontal, tr("file"));
                model->setHeaderData(2, Qt::Horizontal, tr("image_png"));
                model->setHeaderData(3, Qt::Horizontal, tr("category"));
    
                 QSqlQuery* query_new  =  new QSqlQuery(db);
    
                 query_new->prepare("select * from personel");
                 query_new->exec();
                 model->select();
                 ui->sql_table_view->setModel(model);
    

    it is showing the all texts field automatically.

    How can I show image_png sqlite field in this table ?

    ,best

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Do you mean you have a binary blob in the DB that is an image and you want to show that as an image ?
      https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite

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

        @RahibeMeryem said in QSqlTableModel, how to show png images in table:

        QSqlTableModel

        QSqlTableModel . what I need to show images from Sqlite query.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Derive from QSqlTableModel, overwrite data() for Qt::DecorationRole and return the decoded image in there.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Or use a delegate like here: https://forum.qt.io/topic/94494/qsqlquerymodel-and-qpixmap-s-alignment

            In that case pixmapY is static but nothing stops you reading it from index.data()

            "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
            1

            • Login

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