[PyQt] [pyqt5]update sqlite database from qtwidgets.qtablewidget

Maurizio Berti maurizio.berti at gmail.com
Mon Nov 12 20:21:16 GMT 2018


That might depend on the size of the table: according to the Sql driver
support you're using, QSqlTableModel could decide to not load automatically
all data, but only part of it (usually around 500 rows, if I recall
correctly) to increase performance, meaning that resizeRowsToContents will
only resize the items fetched at the time it was called; you can see this
behavior by looking at the extent of the vertical scrollbar, which will
resize as soon as you're reaching the last items fetched, since the
contents of the scrollArea will have changed due to the increased size.
You can do this to ensure that all data is fetched, *before* calling
resizeRowsToContents:

    while model.canFetchMore():
        model.fetchMore()

This obviously is not very well suited for very big data results, as both
the resize*ToContents methods can become very slow in these situations.
Also, keep in mind that if you want all rows to have the same height, you
can also use defaultSectionSize or, better, create your own subclassed
QHeaderView and implement any method that reports sizes (which one depends
on your needs): sectionSize(), sectionSizeFromContents() or
sectionSizeHint().


Il giorno lun 12 nov 2018 alle ore 15:28 Maziar Parsijani <
maziar.parsijani at gmail.com> ha scritto:

> Hi,
> Thanks for that Idea but I have a problem with it when
> resizerowstocontents.
> It doesn't resize all the rows.
>
> On Sun, Nov 11, 2018 at 11:30 PM Maurizio Berti <maurizio.berti at gmail.com>
> wrote:
>
>> Use QSqlTableModel, it's automatically updated according to its
>> EditStrategy.
>>
>

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181112/a5fda1e0/attachment.html>


More information about the PyQt mailing list