#include "mymainwindow.h"
#include <qapplication.h>
widgetstackid1=0;
widgetstackid2=0; //In the real program, this line causes a seg fault.
initLayout();
initMenus();
}
void MyMainWindow::initLayout(){
mainsplitter
=new QSplitter(Qt
::Horizontal,
this);
setCentralWidget(mainsplitter);
leftsplitter
=new QSplitter(Qt
::Vertical,mainsplitter
);
leftPane1=new QListBox(leftsplitter);
leftPane1->insertItem("Item 0");
leftPane1->insertItem("Item 1");
connect(leftPane1,SIGNAL(currentChanged ( QListBoxItem * )),this,SLOT(leftPane1Changed()));
leftPane2=new QListBox(leftsplitter);
mainview=new QWidgetStack(mainsplitter);
createMainWidget1();
createMainWidget2();
}
void MyMainWindow::initMenus(){
fileMenu=new QPopupMenu (this);
viewMenu=new QPopupMenu(this);
fileMenu->insertItem("&Quit",this,SLOT(mnuFileQuit()));
viewMenu->insertItem("View Menu Item",this,SLOT(mnuViewItem()));
menuBar()->insertItem("&File",fileMenu);
menuBar()->insertItem("&View",viewMenu);
}
void MyMainWindow::createMainWidget1(){
QTable *mainWidget1Table = new QTable( 4, 2, mainview );
mainWidget1Table->setLeftMargin(0);
mainWidget1Table->setReadOnly(true);
labels.append("col 1");
labels.append("col 2");
int i;
for(i=0;i<2;i++){
mainWidget1Table->setColumnWidth(i,60);
}
mainWidget1Table->setColumnLabels(labels);
mainWidget1Table->setSorting(true);
mainview->addWidget(mainWidget1Table);
widgetstackid1=mainview->id(mainWidget1Table);
}
void MyMainWindow::createMainWidget2(){
mainWidget2Text->setReadOnly(true);
mainWidget2Text->setText("<h1>hello</h1>world.");
mainview->addWidget(mainWidget2Text);
widgetstackid2=mainview->id(mainWidget2Text); //In the real program, this line causes a seg fault.
}
//Menu functions
void MyMainWindow::mnuViewItem(){
qWarning("mnuViewItem() called.");
}
bool MyMainWindow::mnuFileQuit(){
return (close(true));
}
void MyMainWindow::leftPane1Changed(){
int currentItem=leftPane1->currentItem();
switch(currentItem){
case 0:
mainview->raiseWidget(widgetstackid1);
break;
case 1:
mainview->raiseWidget(widgetstackid2);
break;
}
}
//Main program
int main(int argc,char *argv[]){
MyMainWindow windowThing;
app.setMainWidget(&windowThing);
windowThing.show();
return app.exec();
}
#include "mymainwindow.h"
#include <qapplication.h>
MyMainWindow::MyMainWindow(QWidget *parent,const char *name):QMainWindow(parent,name){
widgetstackid1=0;
widgetstackid2=0; //In the real program, this line causes a seg fault.
initLayout();
initMenus();
}
void MyMainWindow::initLayout(){
mainsplitter=new QSplitter(Qt::Horizontal,this);
setCentralWidget(mainsplitter);
leftsplitter=new QSplitter(Qt::Vertical,mainsplitter);
leftPane1=new QListBox(leftsplitter);
leftPane1->insertItem("Item 0");
leftPane1->insertItem("Item 1");
connect(leftPane1,SIGNAL(currentChanged ( QListBoxItem * )),this,SLOT(leftPane1Changed()));
leftPane2=new QListBox(leftsplitter);
mainview=new QWidgetStack(mainsplitter);
createMainWidget1();
createMainWidget2();
}
void MyMainWindow::initMenus(){
fileMenu=new QPopupMenu (this);
viewMenu=new QPopupMenu(this);
fileMenu->insertItem("&Quit",this,SLOT(mnuFileQuit()));
viewMenu->insertItem("View Menu Item",this,SLOT(mnuViewItem()));
menuBar()->insertItem("&File",fileMenu);
menuBar()->insertItem("&View",viewMenu);
}
void MyMainWindow::createMainWidget1(){
QTable *mainWidget1Table = new QTable( 4, 2, mainview );
mainWidget1Table->setLeftMargin(0);
mainWidget1Table->setReadOnly(true);
QStringList labels;
labels.append("col 1");
labels.append("col 2");
int i;
for(i=0;i<2;i++){
mainWidget1Table->setColumnWidth(i,60);
}
mainWidget1Table->setColumnLabels(labels);
mainWidget1Table->setSorting(true);
mainview->addWidget(mainWidget1Table);
widgetstackid1=mainview->id(mainWidget1Table);
}
void MyMainWindow::createMainWidget2(){
QTextEdit *mainWidget2Text;
mainWidget2Text=new QTextEdit(mainview);
mainWidget2Text->setReadOnly(true);
mainWidget2Text->setText("<h1>hello</h1>world.");
mainview->addWidget(mainWidget2Text);
widgetstackid2=mainview->id(mainWidget2Text); //In the real program, this line causes a seg fault.
}
//Menu functions
void MyMainWindow::mnuViewItem(){
qWarning("mnuViewItem() called.");
}
bool MyMainWindow::mnuFileQuit(){
return (close(true));
}
void MyMainWindow::leftPane1Changed(){
int currentItem=leftPane1->currentItem();
switch(currentItem){
case 0:
mainview->raiseWidget(widgetstackid1);
break;
case 1:
mainview->raiseWidget(widgetstackid2);
break;
}
}
//Main program
int main(int argc,char *argv[]){
QApplication app(argc,argv);
MyMainWindow windowThing;
app.setMainWidget(&windowThing);
windowThing.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks