ich weiss aus http://doc.trolltech.com/4.4/qmainwindow.html dass ein QMainWindow immer ein "central Widget" haben muss. Was mir aus der Doku nicht klar wird was genau dieses central Widget auszeichnet. ist es z.B. wie das Bild im obigen Link meinen koennte das Widget was mittig im QMainWindow dargestellt wird?
Ich habe ein Beispiel der Qt Doku (http://doc.trolltech.com/4.4/painting-basicdrawing.html) in meinen Code zum ausprobieren uebernehmen wollen, der Konstruktor des MainWindows sieht so aus
Code: Alles auswählen
MainWindow::MainWindow(){
QWidget *centralWidget = new QWidget;
renderArea = new RenderArea;
shapeComboBox = new QComboBox;
shapeComboBox->addItem(tr("Polygon"), RenderArea::Polygon);
shapeLabel = new QLabel(tr("&Shape:"));
shapeLabel->setBuddy(shapeComboBox);
penWidthSpinBox = new QSpinBox;
penWidthSpinBox->setRange(0, 20);
penWidthSpinBox->setSpecialValueText(tr("0 (cosmetic pen)"));
penWidthLabel = new QLabel(tr("Pen &Width:"));
penWidthLabel->setBuddy(penWidthSpinBox);
penStyleComboBox = new QComboBox;
penStyleComboBox->addItem(tr("Solid"), Qt::SolidLine);
penStyleLabel = new QLabel(tr("&Pen Style:"));
penStyleLabel->setBuddy(penStyleComboBox);
penCapComboBox = new QComboBox;
penCapComboBox->addItem(tr("Flat"), Qt::FlatCap);
penCapLabel = new QLabel(tr("Pen &Cap:"));
penCapLabel->setBuddy(penCapComboBox);
penJoinComboBox = new QComboBox;
penJoinComboBox->addItem(tr("Miter"), Qt::MiterJoin);
penJoinLabel = new QLabel(tr("Pen &Join:"));
penJoinLabel->setBuddy(penJoinComboBox);
brushStyleComboBox = new QComboBox;
brushStyleComboBox->addItem(tr("Linear Gradient"),Qt::LinearGradientPattern);
brushStyleLabel = new QLabel(tr("&Brush Style:"));
brushStyleLabel->setBuddy(brushStyleComboBox);
otherOptionsLabel = new QLabel(tr("Other Options:"));
antialiasingCheckBox = new QCheckBox(tr("&Antialiasing"));
transformationsCheckBox = new QCheckBox(tr("&Transformations"));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->setColumnStretch(0, 1);
mainLayout->setColumnStretch(3, 1);
mainLayout->addWidget(renderArea, 0, 0, 1, 4);
mainLayout->setRowMinimumHeight(1, 6);
mainLayout->addWidget(shapeLabel, 2, 1, Qt::AlignRight);
mainLayout->addWidget(shapeComboBox, 2, 2);
mainLayout->addWidget(penWidthLabel, 3, 1, Qt::AlignRight);
mainLayout->addWidget(penWidthSpinBox, 3, 2);
mainLayout->addWidget(penStyleLabel, 4, 1, Qt::AlignRight);
mainLayout->addWidget(penStyleComboBox, 4, 2);
mainLayout->addWidget(penCapLabel, 5, 1, Qt::AlignRight);
mainLayout->addWidget(penCapComboBox, 5, 2);
mainLayout->addWidget(penJoinLabel, 6, 1, Qt::AlignRight);
mainLayout->addWidget(penJoinComboBox, 6, 2);
mainLayout->addWidget(brushStyleLabel, 7, 1, Qt::AlignRight);
mainLayout->addWidget(brushStyleComboBox, 7, 2);
mainLayout->setRowMinimumHeight(8, 6);
mainLayout->addWidget(otherOptionsLabel, 9, 1, Qt::AlignRight);
mainLayout->addWidget(antialiasingCheckBox, 9, 2);
mainLayout->addWidget(transformationsCheckBox, 10, 2);
centralWidget -> setLayout(mainLayout);
setCentralWidget(centralWidget); // seg fault hier
}
Danke!