//Public QWidget* Morphology::getLayout(const Operations* op) { mainBox = new QWidget(); QVBoxLayout* currentLayout = new QVBoxLayout(mainBox); currentLayout->setDirection(QBoxLayout::TopToBottom); // Elements for the new layout // Operation QLabel* operationLabel = new QLabel("Operation:",mainBox); operationCombo = new QComboBox(mainBox); operationCombo->addItems(operationsList); //Structuring element QLabel* elementLabel = new QLabel("Structuring Element:",mainBox); structuringElement = new QComboBox(mainBox); structuringElement->addItem("MORPH_RECT"); //Size QLabel* sizeLabel = new QLabel("Size:",mainBox); size = new QSpinBox(mainBox); size->setMinimum(1); size->setValue(1); // iterations QLabel* iterationsLabel = new QLabel("Iterations:",mainBox); iterations = new QSpinBox(mainBox); iterations->setValue(1); // set Layout currentLayout->addWidget(operationLabel); currentLayout->addWidget(operationCombo); currentLayout->addWidget(elementLabel); currentLayout->addWidget(structuringElement); //SubLayout QGridLayout* horizontal = new QGridLayout(mainBox); horizontal->addWidget(sizeLabel,0,0,1,1); horizontal->addWidget(iterationsLabel,0,1,1,1); horizontal->addWidget(size,1,0,1,1); horizontal->addWidget(iterations,1,1,1,1); currentLayout->addLayout(horizontal); mainBox->setLayout(currentLayout); //Connects QObject::connect(operationCombo,&QComboBox::currentTextChanged,op,&Operations::onWidgetChanged); QObject::connect(structuringElement,&QComboBox::currentTextChanged,op,&Operations::onWidgetChanged); QObject::connect(size,SIGNAL_CAST_INT(&QSpinBox::valueChanged),op,&Operations::onWidgetChanged); QObject::connect(iterations,SIGNAL_CAST_INT(&QSpinBox::valueChanged),op,&Operations::onWidgetChanged); //return return mainBox; }
//=========== // PRIVATE //=========== void UserWidget::ClearScrollArea(QScrollArea *area){ QWidget *wgt = area->takeWidget(); delete wgt; //delete the widget and all children area->setWidget( new QWidget() ); //create a new widget in the scroll area area->widget()->setContentsMargins(0,0,0,0); QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(2); layout->setContentsMargins(3,1,3,1); layout->setDirection(QBoxLayout::TopToBottom); area->widget()->setLayout(layout); }
// ========================== // PRIVATE FUNCTIONS // ========================== void StartMenu::ClearScrollArea(QScrollArea *area){ area->takeWidget()->deleteLater(); area->setWidget( new QWidget() ); //create a new widget in the scroll area area->widget()->setContentsMargins(0,0,0,0); QVBoxLayout *layout = new QVBoxLayout; layout->setSpacing(2); layout->setContentsMargins(3,1,3,1); layout->setDirection(QBoxLayout::TopToBottom); layout->setAlignment(Qt::AlignTop); area->widget()->setLayout(layout); }
void motion_selector::setupQuickButtons(QString path) { QFile file(path); std::cout << "Trying to open file at " << path.toStdString() << std::endl; if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { std::cout << "File opened successfully... now parsing." << std::endl; QTextStream in(&file); while(!in.atEnd()) { QString line = in.readLine(); if(line[0] != '#') { QStringList strings; strings = line.split(','); if(strings.size() == 3) { if(strings[0] == QString::fromStdString("space") || strings[0] == QString::fromStdString("Space")) { switch(strings[1].toInt()) { case 1: ui->qb1->insertSpacing(1,strings[2].toInt()); break; case 2: ui->qb2->insertSpacing(1,strings[2].toInt()); break; case 3: ui->qb3->insertSpacing(1,strings[2].toInt()); break; default: std::cout << "malformed spacing in config." << std::endl; } } else { quickButton* newQB = new quickButton(); newQB->button = new QPushButton(); newQB->timeFactor = new QDoubleSpinBox(); newQB->button->setText(strings[1]); newQB->timeFactor->setValue(strings[2].toDouble()); newQB->button->setEnabled(false); newQB->timeFactor->setEnabled(false); newQB->timeFactor->setMaximumWidth(70); connect(newQB->button, SIGNAL(clicked()),this,SLOT(quickButtonClicked())); QVBoxLayout* layout = new QVBoxLayout; layout->setDirection(QBoxLayout::LeftToRight); layout->addWidget(newQB->button); layout->addWidget(newQB->timeFactor); quickButtonList.push_back(newQB); switch(strings[0].toInt()) { case 1: ui->qb1->insertLayout(1,layout,0); break; case 2: ui->qb2->insertLayout(1,layout,0); break; case 3: ui->qb3->insertLayout(1,layout,0); break; default: std::cout << "unknown entry in config for colum" << std::endl; } } } } } } }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget), m_pData(new Widget::Private()) { ui->setupUi(this); QComboBox *cityList = new QComboBox(this); cityList->addItem(tr("Beijing"), QLatin1String("Beijing, cn")); cityList->addItem(tr("Shanghai"), QLatin1String("Shanghai, cn")); cityList->addItem(tr("Nanjing"), QLatin1String("Nanjing, cn")); QLabel* cityLabel = new QLabel(tr("City:"), this); QPushButton *refreshButton = new QPushButton(tr("Refresh"), this); QHBoxLayout *cityListLayout = new QHBoxLayout; cityListLayout->setDirection(QBoxLayout::LeftToRight); cityListLayout->addWidget(cityLabel); cityListLayout->addWidget(cityList); cityListLayout->addWidget(refreshButton); QVBoxLayout *weatherLayout = new QVBoxLayout; weatherLayout->setDirection(QBoxLayout::TopToBottom); QLabel* cityNameLabel = new QLabel(this); weatherLayout->addWidget(cityNameLabel); QLabel *dateTimeLabel = new QLabel(this); weatherLayout->addWidget(dateTimeLabel); m_pData->descLabel = new QLabel(this); weatherLayout->addWidget(m_pData->descLabel); m_pData->iconLabel = new QLabel(this); weatherLayout->addWidget(m_pData->iconLabel); QVBoxLayout* mainLayout = new QVBoxLayout(this); mainLayout->addLayout(cityListLayout); mainLayout->addLayout(weatherLayout); resize(320, 120); setWindowTitle("Weather"); connect(m_pData->network, &NetWorker::finished, [=](QNetworkReply* reply){ switch(m_pData->replyMap.value(reply)) { case FetchWeatherInfo: { QJsonParseError error; QJsonDocument jsonDoc = QJsonDocument::fromJson(reply->readAll(), &error); if(error.error == QJsonParseError::NoError){ if(!(jsonDoc.isNull() || jsonDoc.isEmpty()) && (jsonDoc.isObject())){ QVariantMap data = jsonDoc.toVariant().toMap(); WeatherInfo weather; weather.setCityName(data[QLatin1String("name")].toString()); QDateTime dateTime; dateTime.setTime_t(data[QLatin1String("dt")].toLongLong()); weather.setDateTime(dateTime); QVariantMap main = data[QLatin1String("main")].toMap(); weather.setTempertuare(main[QLatin1String("temp")].toFloat()); weather.setPressure(main[QLatin1String("pressure")].toFloat()); weather.setHumidity(main[QLatin1String("humidity")].toFloat()); QVariantList detaiList = data[QLatin1String("weather")].toList(); WeatherDetailList details; foreach (QVariant w, detaiList) { QVariantMap wm = w.toMap(); WeatherDetail *detail = new WeatherDetail; detail->setDesc(wm[QLatin1String("description")].toString()); detail->setIcon(wm[QLatin1Literal("icon")].toString()); details.append(detail); } weather.setDetails(details); cityNameLabel->setText(weather.cityName()); dateTimeLabel->setText(weather.dateTime().toString(Qt::DefaultLocaleLongDate)); m_pData->descLabel->setText(weather.details().at(0)->desc()); qDebug()<<weather; } else{ QMessageBox::critical(this, "Error","Parse Reply Error!"); } } }