PDA

View Full Version : Trying to implement QMainWindow...



winston2020
23rd October 2008, 16:27
I made a custom widget called MovieTabPane, which eventually will be inside a QTabWidget. But I've been testing it using this:



MovieTabPane *m = new MovieTabPane();
m->show();


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:



ApplicationWindow()
: QMainWindow()
{
// Create MenuBar and Connection Menu
mMenuBar = new QMenuBar( this );
mConnectionMenu = new QMenu( tr("&Connection"), mMenuBar );
mMenuBar->addMenu( mConnectionMenu );

// Create Connect Action, and connect triggered() signal to message() <== temporary
mConnectAction = new QAction( tr("Co&nnect"), mConnectionMenu );
connect( mConnectAction, SIGNAL( triggered() ), this, SLOT( message() ) );

// Create Custom Widget
mMovieTabPane = new MovieTabPane( this );

// Create Grid Layout and add mMovieTabPane
mGridLayout = new QGridLayout( this );
mGridLayout->addWidget( mMovieTabPane );

// Tell AppWindow to use mGridLayout
setLayout( mGridLayout );

// Scale
resize( 905, 495 );

// Show
show();
}


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

spirit
23rd October 2008, 16:37
try this code


ApplicationWindow::ApplicationWindow(QWidget *parent)
: QMainWindow(parent)
{
// Create MenuBar and Connection Menu
QMenu *connectMenu = menuBar()->addMenu(tr("&Connection"));
// Create Connect Action, and connect triggered() signal to message() <== temporary
mConnectAction = new QAction( tr("Co&nnect"), this );
connectMenu->addAction(mConnectAction);
connect( mConnectAction, SIGNAL( triggered() ), this, SLOT( message() ) );

// Create Custom Widget
mMovieTabPane = new MovieTabPane( this );

// Scale
resize( 905, 495 );

setCentralWidget(mMovieTabPane);
}

winston2020
23rd October 2008, 20:12
Thanks! That works perfectly. :D