ich habe ein paar Probleme
Ich erzeuge in einem MainWindow ein Widget vom Typ QWidget. Auf diesem sind RadioButtons vorhanden. Beim Anklicken eines RadioButtons öffnet sich ein weiteres Widget (jetzt mal SubWidgets genannt).
Wenn ich das Widget mit den RadioButtons das erstmal öffne werden die SubWidgets richtig erzeugt. Wenn ich das Widget schließe und erneut öffne, dann öffnen sich beim Anklicken eines RadioButtons jedoch gleich 2 SubWidgets und beim nächsten Öffnen 3 Stück
ich hänge mal meinen Code mit dran
Code: Alles auswählen
#include <QtGui>
#include "mymainwindow.h"
#include "mychild.h"
MyMainWindow::MyMainWindow (QString sTitle)
{
setWindowTitle(sTitle);
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
signalMapper = new QSignalMapper(this);
createActions();
createMenus();
}
void MyMainWindow::createMenus()
{
//Application-Menu
appMenu = menuBar()->addMenu(tr("File"));
appMenu->addAction(newSimAct);
appMenu->addAction(closeSimAct);
appMenu->addSeparator();
appMenu->addAction(closeAppAct);
}
void MyMainWindow::createActions()
{
newSimAct = new QAction (QIcon(":/images/open.png"), tr("New Simulation Session"), this);
connect(newSimAct, SIGNAL(triggered()), this, SLOT(openChild()));
closeAppAct = new QAction (QIcon(":/images/exit.png"), tr("Exit Application"), this);
connect(closeAppAct, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
closeSimAct = new QAction (QIcon(":/images/close.png"), tr("Exit Simulation Session"), this);
connect(closeSimAct, SIGNAL(triggered()), this, SLOT(closeSim()));
}
void MyMainWindow::openChild()
{
if (activeChild()) return;
session = new MyChild("Simulation Modules");
//GroupBox festlegen
QGroupBox *gbSource = new QGroupBox(tr("Source"));
QRadioButton *rbTophat = new QRadioButton(tr("Tophat"));
QRadioButton *rbProcess = new QRadioButton(tr("Processed Measured"));
QRadioButton *rbSynthes = new QRadioButton(tr("Synthesized Physical"));
connect(rbTophat, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(rbTophat, 0);
connect(rbProcess, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(rbProcess, 1);
connect(rbSynthes, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(rbSynthes, 2);
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(openModule(int)));
connect(session, SIGNAL(), this, SLOT(closeSim()));
QVBoxLayout *blSource = new QVBoxLayout;
blSource->addWidget(rbTophat);
blSource->addWidget(rbProcess);
blSource->addWidget(rbSynthes);
gbSource->setLayout(blSource);
QGridLayout *grid = new QGridLayout;
grid->addWidget(gbSource,0,0);
grid->setSizeConstraint(QLayout::SetMinimumSize);
session->setLayout(grid);
mdiArea->addSubWindow(session);
session->show();
}
void MyMainWindow::openModule(int whichModule)
{
switch(whichModule)
{
case 0:
sourceModul = new MyChild("Tophat");
break;
case 1:
sourceModul = new MyChild("Processed Measured");
break;
case 2:
sourceModul = new MyChild("Synthesized Physical");
break;
}
mdiArea->addSubWindow(sourceModul);
sourceModul->show();
}
void MyMainWindow::closeSim()
{
mdiArea->closeAllSubWindows();
}
bool MyMainWindow::activeChild()
{
if(QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow())
return true;
return false;
}Was erzeugt diesen seltsamen Effekt?
Anregungen für einen besseren Programmierstil werden auch gern entgegen genommen.
Vielen Dank für eure Hilfe.
Viele Grüße
Jana