Python Forum
[PyQt] QStyledItemDelegate and QTableView - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] QStyledItemDelegate and QTableView (/thread-38304.html)



QStyledItemDelegate and QTableView - malonn - Sep-27-2022

I have subclassed QStyledItemDelegate, reimplemented initStyleOption and set it to a QTableView. Everything works as expected, but I don't understand something. I noticed that on launch of the GUI, the initStyleOption runs 3 full times for one view, however, the __init__ method runs once, as I assumed initStyleOption would (per item in the view/model, of course). Why does it do that?

By printing to console, I noticed that when the GUI loads, initStyleOption gets called once per row in view, then once per item in the view, then again once per item in the view. Is this normal behavior? I'm refraining from sharing code for a couple of reasons, including the code works, and it's a multi-module project and would take a little effort to extract the relevant snippets. I can and will, however, if it helps someone diagnose the "issue" (if it is an issue).

Thanks for any insight.


RE: QStyledItemDelegate and QTableView - malonn - Feb-07-2023

Necro-post. Sorry for bad form, but I discovered that running a QStyledItemDelegate in a table is supposed to happen multiple times per view. It is expected behavior. I'm not sure why, but I would assume a reimplemented initStyleOption would be called once for every cell, and then again (and maybe again after that depending on other code. So, it never was an "issue" for me, I just didn't know it is expected.