python - PyQt obtaining collection of all registered fields in QWizard -
i working on simple qwizard
displays radio buttons on pages. buttons on given page part of same qbuttongroup
. page registered custom field in itself, based on selection in button group:
class page1(qwizardpage): selectionchanged = pyqtsignal('qstring') def __init__(self, name): self.group = qbuttongroup() self.group.addbutton(qradiobutton("a")) self.group.addbutton(qradiobutton("b")) self.group.addbutton(qradiobutton("c")) self.registerfield(name, self, 'selection', self.selectionchanged) @pyqtproperty('qstring') def selection(self): checkedbutton = self.group.checkedbutton() return checkedbutton.text() if checkedbutton else none def nextid(self): return -1
i end registering self
widget containing field property because qbuttongroup
not qwidget
. of other pages pretty (i using base class common work, , minimal example).
i able list of registered fields in qwizard
. have not found methods provided qt allow me made workaround overriding behavior of each page's registerfield
method wizard's addpage
:
def registerfield(self, name, *args, **kwargs): self.field_names.add(name) if self.wizard() not none: self.wizard().field_names.add(name) super().registerfield(name, *args, **kwargs)
def addpage(self, page, *args, **kwargs): self.field_names.union(page.field_names) return super().addpage(page, *args, **kwargs)
i can use field_set
attribute of parent qwizard
combined qwizard.field
access values. seems bit redundant , therefore unnecessary. is there method in qt access complete collection of fields? relevant section in documentation not mention anything, there lot of other details omits, that's not telling.
my assumption functionality, if exists, same pyqt4 pyqt5. if not, prefer answer pyqt5 since using @ moment.
you said if answer negative have "pretty convincing." admit documentation contains no mention of function want, , point out no such function appears in list of public functions qwizard. therefore desired function, if exists @ all, undocumented. me, consideration alone "pretty convincing" reason not use it. next release of qt might not have function, or might not work same way.
meanwhile have acceptable solution 8 lines of straightforward python code. given choice between , calling undocumented function (if can find it), python solution vastly superior in practical respects.
there potential problem python code, however. override function qwizard.addpage
, there function qwizard.removepage
should overridden well. alternative approach, prefer, not store field_names in qwizard
@ in individual pages. add method qwizard dynamically build set of current field_names:
def all_field_names(self): return {s page_id in self.pageids() s in self.page(page_id).field_names}
[i didn't have way of testing function, think idea.] remove overridden method qwizard.addpage
, remove variable field_names
qwizard
, , remove middle 2 lines of register_field
. have 5 lines of python code, work regardless of how pages added or removed. , no longer store field names in 2 places.
for it's worth, whenever i'm confronted choice between using qt's functionality or basic python functionality, lean toward python. use threads instead of qthreads, threading locks , timers instead of qt equivalents, python method objects , callbacks instead of custom slots , signals. qt written c++ programmers , means it's not "pythonic" like.
Comments
Post a Comment