Results 1 to 3 of 3

Thread: Trying to implement QMainWindow...

  1. #1
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Trying to implement QMainWindow...

    I made a custom widget called MovieTabPane, which eventually will be inside a QTabWidget. But I've been testing it using this:

    Qt Code:
    1. MovieTabPane *m = new MovieTabPane();
    2. m->show();
    To copy to clipboard, switch view to plain text mode 

    Which has worked fine. But now, I'm adding the QMainWindow, and trying to put the MovieTabPane on as the central widget with a QMenuBar. The entire window comes out empty except the menu bar and widget, which are cramped into the top left corner.

    Here's the code:

    Qt Code:
    1. ApplicationWindow()
    2. {
    3. // Create MenuBar and Connection Menu
    4. mMenuBar = new QMenuBar( this );
    5. mConnectionMenu = new QMenu( tr("&Connection"), mMenuBar );
    6. mMenuBar->addMenu( mConnectionMenu );
    7.  
    8. // Create Connect Action, and connect triggered() signal to message() <== temporary
    9. mConnectAction = new QAction( tr("Co&nnect"), mConnectionMenu );
    10. connect( mConnectAction, SIGNAL( triggered() ), this, SLOT( message() ) );
    11.  
    12. // Create Custom Widget
    13. mMovieTabPane = new MovieTabPane( this );
    14.  
    15. // Create Grid Layout and add mMovieTabPane
    16. mGridLayout = new QGridLayout( this );
    17. mGridLayout->addWidget( mMovieTabPane );
    18.  
    19. // Tell AppWindow to use mGridLayout
    20. setLayout( mGridLayout );
    21.  
    22. // Scale
    23. resize( 905, 495 );
    24.  
    25. // Show
    26. show();
    27. }
    To copy to clipboard, switch view to plain text mode 

    I'll be back in a few hours to check replies... gotta go write a Physics mid term

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Trying to implement QMainWindow...

    try this code
    Qt Code:
    1. ApplicationWindow::ApplicationWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. {
    4. // Create MenuBar and Connection Menu
    5. QMenu *connectMenu = menuBar()->addMenu(tr("&Connection"));
    6. // Create Connect Action, and connect triggered() signal to message() <== temporary
    7. mConnectAction = new QAction( tr("Co&nnect"), this );
    8. connectMenu->addAction(mConnectAction);
    9. connect( mConnectAction, SIGNAL( triggered() ), this, SLOT( message() ) );
    10.  
    11. // Create Custom Widget
    12. mMovieTabPane = new MovieTabPane( this );
    13.  
    14. // Scale
    15. resize( 905, 495 );
    16.  
    17. setCentralWidget(mMovieTabPane);
    18. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trying to implement QMainWindow...

    Thanks! That works perfectly.

Similar Threads

  1. QMainWindow modal from non-qt window?
    By hickscorp in forum Qt Programming
    Replies: 3
    Last Post: 21st November 2008, 09:10
  2. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 13:00
  3. QMainWindow child of a QDialog
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2008, 07:16
  4. What's the best way to implement a MainWindow
    By darkadept in forum Qt Programming
    Replies: 5
    Last Post: 5th February 2007, 17:46
  5. Replies: 18
    Last Post: 22nd February 2006, 20:51

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.