Results 1 to 4 of 4

Thread: General approach for a document-based app

  1. #1
    Join Date
    Feb 2007
    Posts
    27
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default General approach for a document-based app

    Here's what I'm trying to create:
    • Application without a document open is a single window with a menu bar.
    • The first document replaces that window.
    • Subsequence documents open an entirely new window.
    • The program doesn't close until all windows are closed.
    • On Mac OS X, the behavior is much the same, except I don't want to see an empty window. Instead, I just have the menu bar. Also, closing the last window wouldn't close the program.


    What's the general approach for this kind of application?

  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: General approach for a document-based app

    It depends what you call an "approach". In general you want to implement an SDI interface with each document in a separate window. The answer is to keep all the document related data inside the window and spawn new windows (and documents) when a new document is requested. So you need a kind of "controller" object that will spawn windows and the windows themselves. Probably the "new", "open" and "close" actions of each window should be connected to the controller somehow (either they should reside in the controller and all windows would share the actions or each window has its own set of actions and emits a signal to the controller that a new document was requested).
    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. #3
    Join Date
    Feb 2007
    Posts
    27
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: General approach for a document-based app

    Right, it's basically an SDI interface, but I want it to work well on Mac OS X, too. If you can imagine, say, Microsoft Word on Windows pre-ribbon and Microsoft Word on Mac you've basically got the idea. It's a very standard UI.

    What I don't understand is which Qt classes to use.
    • If I use QMainWindow, I'll always have a window open, including on Mac OS X. This isn't a good solution, though maybe I can have some sort of welcome screen that hides itself when a document is opened.
    • If I use a QWidget subclass, closing the last window will close the application, plus I won't get an acceptable "empty" window on Windows and Linux. Plus I'll need to implement the menu bar entirely in code.

    I have some experience writing Qt applications, but so far they've been a single main window configuration UI and I haven't dealt with a document-based application. On the other hand, I have experience writing document-based applications, just not on Qt. It's the intersection of how to do document-based with Qt's GUI classes that I'm drawing a blank at.

    I've been looking through the examples, but haven't seen anything applicable yet. The webbrowser sample looks the closest to what i want, but when all windows are closed on the Mac it loses its menu bar.
    Last edited by sdfisher; 29th March 2009 at 06:57.

  4. #4
    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: General approach for a document-based app

    Let's clear some things.
    1. QMainWindow is a QWidget subclass
    2. Closing last widget will not exit the application if you disconnect the lastWindowClosed() signal from the quit() slot in the application regardless of the window types you use
    3. In Qt menu bar is related to some window, so without a window you won't have a menu bar
    4. You might get away with having an invisible or out-of-screen window to have a menu bar but this is not an optimal solution. It might be better to spawn the menu with native code or to look for an attribute in Qt allowing to do so. I would also try instantiating a floating QMenuBar object and see if it is enough to move the menu bar to the top of the screen.
    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.


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.