Otto_Hirr | 2021-04-07 15:18:58 UTC | #1
I have a subclass of QAbstractTableModel
which correctly calls data()
and setData()
but does not call flags()
.
Since it is correctly calling data()
& setData()
, I presume the initialization should be correct for the QAbstractTableModel
as a parent class of the object. I'm also using PyCharm, and it correctly shows an icon indicating which methods are being overridden.
I have another class with QAbstractTableModel
as a parent class and it operates correctly. Debugging print statements flood the console in moving the mouse. So I presume something is up with the implementation of the other class.
The primary difference between the working/non-working classes is that the non-working class has multiple inheritance, defined as class A( B, QAbstractTableModel )
The other class has single inheritance as class C( QAbstractTableModel )
Since PyCharm seems to parse and identify overridden methods correctly and since the data() and setData()
are working, I presume that initialization of the parent classes of A are correct.
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.
Any suggestions on debugging would be appreciated.
Best regards, ..Otto
Otto_Hirr | 2021-04-07 15:22:38 UTC | #2
I'm guessing that a QLineEdit
, accessing a class derived from QAbstractTableModel
, using the QDataWidgetMapper
, does not call the flags()
method of the QAbstractTableModel
.
The doc https://doc.qt.io/qt-5/modelview.html describes standard widgets and MV widgets and depicts under section 1.3 Overview of the Model/View Widgets.
It goes on to describe adapters, section 1.4 Using Adapters between Forms and Models, and references example widget QLineEdit
.
I'm going to speculate that the QDataWidgetMapper
will fetch and set data managed under QAbstractItemModel
and the associated derived classes, eg QAbstractTableModel
which I'm using, however the QDataWidgetMapper
will not be making flags() calls to set the params of widgets, such as QLineEdit
.
Any other thoughts?
..Otto
martin | 2021-04-07 15:29:31 UTC | #3
Hi @Otto_Hirr welcome to the forum & apologies for the delay in responding, I misses this when it first came in.
I think you've hit the nail on the head re: QLineEdit
. The flags()
are only really relevant to the model views which are designed to handle them. The flags are requested from the model when required by the view, but standard widgets have no mechanism to do this. The QDataWidgetMapper
would be the place to look for this perhaps, as that does know about the flags mechanism and could feasibly apply changes to the widget (e.g. checkbox tristate).
Which flags were you hoping to apply to the QLineEdit
, perhaps we can work something out.
Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.