Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, November 2007
QT3 - QMainWindow Help - Not Showing Widgets


Message 1 in thread

First, I'm going to let you know that I'm very new to QT.  I've used
wxWidgets before, and feel very comfortable, but I wanted to learn
something new.

Most of you are probably familiar with the Amarok program.  It's a
pretty complex media management software written in QT.

My end goal is to try and emulate the interface as much as possible.
The interface includes two panes, one for the current collection, and
one for the current playlist.  I was doing fairly well until I tried to
get a QMenuBar added.  I found that QMainWindow seems to be the
solution of choice for what I'm trying to do (if not, please steer me
in the right direction).  I'll also note that I'm using QT3, because I
can't figure out the QListView in QT4 (only QTreeView has columns?)

The problem I'm having is that the mainWindow class is showing up, it's
just not showing any contents.  I'm not sure if I'm missing a call or
what.

Here's my current code:
#include <qapplication.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qmenubar.h>
#include <qlistview.h>
#include <qsplitter.h>
#include <qlineedit.h>
#include <qmainwindow.h>

class leftPane: public QWidget{
Q_OBJECT
public: 
	leftPane( QWidget *parent=0);
};

leftPane::leftPane(QWidget *parent):QWidget(parent){


	QGridLayout *leftSide = new QGridLayout(this);
	leftSide->setSpacing(5);

	QHBoxLayout *searchLayout = new QHBoxLayout(this);
	QLineEdit *searchBox = new QLineEdit(this);
	QPushButton *clearSearch = new QPushButton("Clear", this);
	searchLayout->addWidget(searchBox);
	searchLayout->addWidget(clearSearch);

	QListView *library = new QListView(this);
	library->addColumn("Artist");
	library->addColumn("Title");
	library->addColumn("Album");

	QPushButton *btn = new QPushButton( "Show Search Panel", this);
	QPushButton *speakSelect = new QPushButton("Select Speaker",
this); leftSide->addWidget(speakSelect, 0,0);
	leftSide->addLayout(searchLayout, 1,0);
	leftSide->addWidget(library, 2,0);
	leftSide->addWidget(btn, 3,0);
}

class rightPane: public QWidget{
Q_OBJECT
public: 
	rightPane( QWidget *parent=0);
};

rightPane::rightPane( QWidget *parent):QWidget(parent){
	QGridLayout *rightSide = new QGridLayout(this);
	QListView *playlist = new QListView(this);
	playlist->addColumn("Artist");
	playlist->addColumn("Title");
	playlist->addColumn("Album");
	rightSide->addWidget(playlist, 1,0);
}

class mainWindow: public QMainWindow{
    Q_OBJECT
public:
	mainWindow( QWidget *parent=0);
};

mainWindow::mainWindow(QWidget *parent): QMainWindow(parent){
	setCaption("Triplet");
	QSplitter *split = new QSplitter();
	leftPane *lpane = new leftPane(split);
	rightPane *rpane = new rightPane(split);
	setCentralWidget(split);
	resize(300,500);
}

int main( int argc, char **argv )
{
    QApplication a( argc, argv );
	mainWindow *mw = new mainWindow();
	mw->show();
	QObject::connect(&a, SIGNAL(lastWindowClosed()), &a,
SLOT(quit())); return a.exec();
}

#include "main.moc"

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: PGP signature


Message 2 in thread

Cody Harris wrote:
[...]
> The problem I'm having is that the mainWindow class is showing up, it's
> just not showing any contents.  I'm not sure if I'm missing a call or
> what.
[...]
> mainWindow::mainWindow(QWidget *parent): QMainWindow(parent){
> 	setCaption("Triplet");
> 	QSplitter *split = new QSplitter();
> 	leftPane *lpane = new leftPane(split);
> 	rightPane *rpane = new rightPane(split);
> 	setCentralWidget(split);
> 	resize(300,500);
> }

Your QSplitter widget does not have a parent. I'm not sure if 
setCentralWidget() will re-parent it. Did you try explicitly parenting 
the splitter with the main window?

Martin.

--
 [ signature omitted ]