Mysterious ".widget" method
-
Re: add buttons in tablewidget's row
On the fourth line inside the paint method from the VRonin suggested solution there is a strange "option.widget" entry. The "option" object is of the type QStyleOptionViewItem and yet qtWiki shows no sign of that particular method for the type.
If this is not a method then what is it? -
It's called member variable.
-
@Christian-Ehrlicher
QStyleOptionViewItem::widget
is declared public at https://codebrowser.dev/qt6/qtbase/src/widgets/styles/qstyleoption.h.html#QStyleOptionViewItem::widget. However even from List of All Members for QStyleOptionViewItem there is no mention ofwidget
, though other member variables are documented. Is this a documentation oversight?UPDATE
It looks like it was removed from documentation at some point. @VRonin's post would have been written at Qt5. It's hard to find old documentation, but I see at least at Qt5.7 from https://stuff.mit.edu/afs/athena/software/texmaker_v5.0.2/qt57/doc/qtwidgets/qstyleoptionviewitem-members.html it was mentioned there, though I think clicking it (https://stuff.mit.edu/afs/athena/software/texmaker_v5.0.2/qt57/doc/qtwidgets/qstyleoptionviewitem.html#widget-var) leads nowhere? -
widget was never documented (not even in Qt4 days -> https://github.com/qt/qt/blob/4.8/src/gui/styles/qstyleoption.cpp
But this does not change the fact that it's a member of QStyleOptionViewItem as this was the question:
If this is not a method then what is it?
-
@Christian-Ehrlicher OK. But @VRonin chose to use it and the rest of us did not know it exists :)
-
-
But it's clearly there (in Qt5) ;-)
Might even be a bug in the documentation back then... or left out on purpose because besides it's a public member, it wasn't intended to get accessed by any user ofQStyleOptionViewItem
API...?!
Seems like we don't know :) -
@JonB said in Mysterious ".widget" method:
I suspect that, but @VRonin found it useful :)
Oh well, after following your link to the Qt6 source I just realized that it's still present.
At first I suspected that it might have been a Qt4/Qt5 thing... but everything still applies until today :DI'm wondering if and how many more cases like this exist... mhh...
(so things that are technically possible, but almost everybody forgot about due to not being documented and still part of the API) -
widget and locale was added in Qt4 times but never documented. Working on it.
-
@Pl45m4
This does not explain the choice of which to document and which not, but the issue might be partly related to how QStyleOptionViewItem is implemented/documentedFor performance reasons, there are few member functions and the access to the member variables is direct (i.e., using the . or -> operator). This makes the structures straightforward to use and emphasizes that these are simply parameters used by the style functions.
It's an "unusual" Qt case where they let you access member variables directly.
-
@JonB said in Mysterious ".widget" method:
It's an "unusual" Qt case where they let you access member variables directly.
But not that unusual when looking at the class' name...
QStyle
Option
ViewItem
.
You could break that down to a simple struct containing a dumped collection of "options", flags / enums etc... in this case having only public members is not that uncommon. -
If someone wants to proof-read the doc: https://codereview.qt-project.org/c/qt/qtbase/+/611693