PDA

View Full Version : QMenuBar and Model/View Concept



rubikon
20th July 2012, 11:29
Hello.

I want to separate the business-logic of my application from the GUI. So I can easily implement a GUI for desktop PCs and PC with touchscreens (or some other devices in the future).

As most applications my application should have some kind of main menu. This main menu should be able change (quite often), depending on some conditions.

The desktop GUI should just use QMenuBar and my touch GUI should use a custom widget which I wrote. This is basically a bar with large tool buttons which contains texts like 'file', 'edit' and so on and up popping bars which contains the corresponding 'subitems' like 'new', 'save', 'close'...

My idea is to provide the current main menu as model (because the menu can change) and the GUI displays it as view. Is this possible?

I guess I have to inherit from QAbstractTableModel for my model, from QAbstractItemView and QMenuBar for my desktop view and from QAbstractItemView for my touchscreen view. Is this idea correct? Can someone give me a ruff roadmap how to achieve model/view -> menu connection?

Sorry for this basic questions. I'm absolutely new to the model/view concept.

wysota
20th July 2012, 11:42
My idea is to provide the current main menu as model (because the menu can change) and the GUI displays it as view. Is this possible?
I don't see why wouldn't it be.


I guess I have to inherit from QAbstractTableModel for my model,
It depends if you want the menu to be flat or have submenus.


from QAbstractItemView and QMenuBar for my desktop view and from QAbstractItemView for my touchscreen view. Is this idea correct?
No. You can't inherit from two widget classes at once and besides there is no point in using QAbstractItemView here. Just make your infrastructure "talk" directly to the model. You don't even need to subclass QMenuBar, just have a component that will populate an existing menu bar.

There is a bunch of signals in the model API you need to connect to to be notified when data is added/removed from the model. Then update your menu accordingly.