PDA

View Full Version : QTableWidget relocate data



Kasea
15th June 2017, 14:55
So I have a table widget that's 4x4 which results in 16 data entries(these data entries are qwidgets). Then when i fullscreen I will have 8x2, what is the most efficient way of doing this?

Currently I'm clearing the table out and then adding the items again from scratch, however when the numbers scale up this is an extremely inefficient method of doing it.

Note: I tried to thread this process and then run QApplication.processEvents() to avoid the "lag" feeling, however when i did this everything else on the window would get shifted out of place if i resized the window fast in succession.

d_stranz
15th June 2017, 19:17
I don't know of any way to do this except in the way you have described. QTableWidget isn't really intended to be dynamically reconfigured like that - you aren't actually using it as a table with defined columns, your use is more of a linear array of cells that you flow from left to right and top to bottom depending on your window size. Your "table" doesn't really have the concept of a "row" because you slide things from row to row and column to column as the size of the window changes.

You should take a look at the Flow Layout example (https://doc.qt.io/qt-5/qtwidgets-layouts-flowlayout-example.html), which demonstrates the kind of behavior you are looking for. Substitute QLabel for the QPushButton items in the example, set the margins and sizes appropriately, and I think it will do what you want.