DiagramWindow::DiagramWindow(){ createToolBox(); scene = new QGraphicsScene(0, 0, QApplication::desktop()->width(), QApplication::desktop()->height()); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(toolBox); view = new QGraphicsView(scene); layout->addWidget(view); QWidget *widget = new QWidget; widget->setLayout(layout); .... setCentralWidget(widget);}void DiagramWindow::createToolBox(){ QGridLayout *layout = new QGridLayout; QGroupBox *groupBox1= new QGroupBox; QGroupBox *groupBox2= new QGroupBox; QGroupBox *groupBox3= new QGroupBox; groupBox1->setTitle(codec->toUnicode("Параметр")); groupBox2->setTitle(codec->toUnicode("Показать")); groupBox3->setTitle(codec->toUnicode("Показать")); QRadioButton *radioButton1 = new QRadioButton; QRadioButton *radioButton2 = new QRadioButton; radioButton1->setChecked(true); radioButton1->setText("1"); radioButton2->setText("2"); QVBoxLayout *vbox1 = new QVBoxLayout; vbox1->addWidget(radioButton1); vbox1->addWidget(radioButton2); vbox1->addStretch(1); groupBox1->setLayout(vbox1); layout->addWidget(groupBox1); QRadioButton *radioButton3 = new QRadioButton; QRadioButton *radioButton4 = new QRadioButton; QRadioButton *radioButton5 = new QRadioButton; QRadioButton *radioButton6 = new QRadioButton; QRadioButton *radioButton7 = new QRadioButton; QRadioButton *radioButton8 = new QRadioButton; radioButton3->setChecked(true); radioButton3->setText(codec->toUnicode("Расчет1")); radioButton4->setText(codec->toUnicode("Расчет2")); radioButton5->setText(codec->toUnicode("Расчет3")); radioButton6->setText(codec->toUnicode("Расчет4")); radioButton7->setText(codec->toUnicode("Расчет5")); radioButton8->setText(codec->toUnicode("Расчет6")); QVBoxLayout *vbox2 = new QVBoxLayout; vbox2->addWidget(radioButton3); vbox2->addWidget(radioButton4); vbox2->addWidget(radioButton5); vbox2->addWidget(radioButton6); vbox2->addWidget(radioButton7); vbox2->addWidget(radioButton8); vbox2->addStretch(1); groupBox2->setLayout(vbox2); layout->addWidget(groupBox2); QRadioButton *radioButton9 = new QRadioButton; QRadioButton *radioButton10= new QRadioButton; QRadioButton *radioButton11= new QRadioButton; QRadioButton *radioButton12= new QRadioButton; QRadioButton *radioButton13= new QRadioButton; QRadioButton *radioButton14= new QRadioButton; radioButton9->setChecked(true); radioButton9->setText(codec->toUnicode("Измерение1")); radioButton10->setText(codec->toUnicode("Измерение2")); radioButton11->setText(codec->toUnicode("Измерение3")); radioButton12->setText(codec->toUnicode("Измерение4")); radioButton13->setText(codec->toUnicode("Измерение5")); radioButton14->setText(codec->toUnicode("Измерение6")); QVBoxLayout *vbox3 = new QVBoxLayout; vbox3->addWidget(radioButton9); vbox3->addWidget(radioButton10); vbox3->addWidget(radioButton11); vbox3->addWidget(radioButton12); vbox3->addWidget(radioButton13); vbox3->addWidget(radioButton14); vbox3->addStretch(1); groupBox3->setLayout(vbox3); layout->addWidget(groupBox3); layout->setRowStretch(3, 10); layout->setColumnStretch(1, 10); connect(radioButton1, SIGNAL(clicked(bool)), this, SLOT(Toggled_1())); connect(radioButton2, SIGNAL(clicked(bool)), this, SLOT(Toggled_2())); QWidget *itemWidget = new QWidget; itemWidget->setLayout(layout); toolBox = new QToolBox; toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored)); toolBox->setMinimumWidth(itemWidget->sizeHint().width()); toolBox->addItem(itemWidget, tr(""));}void DiagramWindow::Toggled_1(){groupBox3->hide();}void DiagramWindow::Toggled_2(){ groupBox2->hide();}
bool DiagramWindow::eventFilter(QObject *, QEvent *event){ if(event->type() == QEvent::Resize ) { view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); return true; } return false;}