[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] retrieving images(blob) from sqlite db
From:       michael h <michaelkenth () gmail ! com>
Date:       2019-08-24 16:13:58
Message-ID: CAD0nt=FT8EtJk3EqjzSyyqAEoaCxPrX_ZJM6gy2R3b1Rt3QKwg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Sat, Aug 24, 2019 at 4:39 AM Ali M <adeadmarshal@gmail.com> wrote:

> I've created a sqlite db with a blob field and put images in it. how can i
> retrieve the images and show them in a qtextbrowser? i want to get the
> images with a for loop something like the below code but i don't know how.
>
> def readImage(self):
>         cur = self.db.cursor()
>         rows = cur.execute("select cover from covers")
>         pm = QPixmap()
>         for row in rows:
>                 pic = self.ui.label.setPixmap(QPixmap("row.jpg"))
>                 self.ui.textBrowser.insertFromMimeData(pic)
>

You can use loadFromData(thebytes) to load a QPixmap from bytes, however
you may use a QImage (which also has loadFromData) and
https://doc.qt.io/qt-5/qtextcursor.html#insertImage-3 because it looks
easier to me

(insertFromMimeData won't work on a QPixmap anyhow AFAICT)

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Sat, Aug 24, 2019 at 4:39 AM Ali M &lt;<a \
href="mailto:adeadmarshal@gmail.com">adeadmarshal@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="ltr">I&#39;ve created a sqlite db with a blob field and put images in it. how \
can i retrieve the images and show them in a qtextbrowser? i want to get the images \
with a for loop something like the below code but i don&#39;t know \
how.<br><div><br></div><div>def readImage(self):<br>            cur = \
self.db.cursor()<br>            rows = cur.execute(&quot;select cover from \
covers&quot;)<br>            pm = QPixmap()<br>            for row in rows:<br>       \
pic = self.ui.label.setPixmap(QPixmap(&quot;row.jpg&quot;))<br>                       \
self.ui.textBrowser.insertFromMimeData(pic)<br></div></div></blockquote><div><br></div><div>You \
can use loadFromData(thebytes) to load a QPixmap from bytes, however you may use a \
QImage (which also has loadFromData) and  <a \
href="https://doc.qt.io/qt-5/qtextcursor.html#insertImage-3">https://doc.qt.io/qt-5/qtextcursor.html#insertImage-3</a> \
because it looks easier to me</div><div><br></div><div>(insertFromMimeData won&#39;t \
work on a QPixmap anyhow AFAICT)</div><div><br></div></div></div>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic