PDA

View Full Version : Menubar implementation



JanW
14th April 2016, 08:41
Hi,

I'm trying to understand the inner working of the menubar control (not how to use it, but how it is implemented). I already figured out that MenuBar.qml uses MenuBarPrivate, which is actually a QQuickMenuBar object (same for the Menu - QQuickMenu). What I'm failing to understand is how the MenuBar uses the Menu components which are defined inside. I can see that the MenuBar uses a Repeater (model is the QQuickMenuBar menus property), but I can't figure out how that list is populated with the menus that are defined in the MenuBar component.
Anybody an idea how that is done, I'm sure i'm overlooking something stupid...
Thanks,

Jan

anda_skoa
14th April 2016, 09:19
I haven't looked at the menu bar implementation,. but usually the type that handles "children" is QQmlListProperty.

Cheers,
_

JanW
14th April 2016, 10:14
Yes, that i figured out. There is a QProperty in the QQuickMenuBar "menus" which is indeed a QQmlListProperty. The MenuBar control uses this in a repeater to visualize the menu. That I already understood, but what I don't understand is how that QQmlListProperty is populated with the childcomponents that you define in your MenuBar...

Jan

anda_skoa
14th April 2016, 10:41
That "menus" property is likely marked as the "default" property, so writing this


MenuBar {
Menu {}
Menu {}
}

is equivalent to


MenuBar {
menus: [ Menu {}, Menu {} ]
}

Two instance of Menu get created and appended to the "menus" QQmlListProperty.

Cheers,
_

JanW
14th April 2016, 11:11
Yes, that's it probably. In the qquickmenubar I see: Q_CLASSINFO("DefaultProperty", "menus"). I didn't know about the default property.
Thanks!

Jan