Results 1 to 2 of 2

Thread: QMenuBar and Model/View Concept

  1. #1
    Join Date
    Sep 2010
    Posts
    36
    Thanks
    1

    Default QMenuBar and Model/View Concept

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMenuBar and Model/View Concept

    Quote Originally Posted by rubikon View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    rubikon (20th July 2012)

Similar Threads

  1. Replies: 4
    Last Post: 18th April 2012, 18:11
  2. Replies: 1
    Last Post: 24th February 2011, 05:54
  3. Replies: 0
    Last Post: 21st April 2010, 12:23
  4. Replies: 1
    Last Post: 1st February 2010, 18:42
  5. QSql Model-View: How to keep view in sync with model
    By schall_l in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2008, 23:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.