void GroupSelWidget::sceneChanged() { QSet<QString> groupSet = _scene->getAllGroups(); if(groupSet == _prevGroupSet) return; _prevGroupSet = groupSet; QList<QString> groups = groupSet.toList(); qSort(groups); for(int i = 0; i < (int)_checkBoxes.size(); ++i) delete _checkBoxes[i]; _checkBoxes.clear(); int childWidth = 0; for(int i = 0; i < (int)groups.size(); ++i) { QCheckBox *box = new QCheckBox(groups[i], this); QFont font = box->font(); font.setPointSize(14); box->setFont(font); box->setCheckState(_scene->isGroupVisible(groups[i]) ? Qt::Checked : Qt::Unchecked); new VisibilitySetter(box, _scene, groups[i]); layout()->addWidget(box); childWidth = max(childWidth, box->sizeHint().width()); _checkBoxes.push_back(box); } setMinimumWidth(150); QWidget *scrollArea = parentWidget()->parentWidget()->parentWidget(); scrollArea->setMinimumWidth(childWidth + 20); }
//加载完成 void SearchThread::slot_LoadFinished( QNetworkReply *replay ) { QTextCodec *codec = QTextCodec::codecForName("utf8"); //转换成utf8编码格式 QString searchStr = codec->toUnicode(replay->readAll()); if (searchStr == "") { emit sig_SearchTimeout(); //搜索超时 return; } searchStr = QUrl::fromPercentEncoding(searchStr.toAscii()); //百分比编码 //解析Json QJson::Parser parser; bool ok; QVariantMap result = parser.parse(searchStr.toUtf8(), &ok).toMap(); if (!ok) { qDebug() << "转换成QVariantMap失败"; return; } //搜索到的数量 m_nMusicNum = result["total"].toInt(); emit sig_SearchNum(m_nMusicNum); //得到结果数组 QVariantList resultList = result["results"].toList(); foreach (QVariant var, resultList) { QVariantMap resultMap = var.toMap(); //得到每一项的map //歌曲名 QCheckBox *musicNameCheckBox = new QCheckBox(resultMap["song_name"].toString()); musicNameCheckBox->setObjectName(tr("musicNameCheckBox")); musicNameCheckBox->setToolTip(resultMap["song_name"].toString()); musicNameCheckBox->setFont(QFont("微软雅黑", 10)); musicNameCheckBox->setStyleSheet("QCheckBox{color:white;}" "QCheckBox::indicator{width:10px;height:10px;border: 1px solid white;border-radius:2px}" "QCheckBox::indicator:checked {image: url(:/app/images/checked2.png);}"); //艺人 QTableWidgetItem *artistItem = new QTableWidgetItem(resultMap["artist_name"].toString()); artistItem->setTextAlignment(Qt::AlignCenter); artistItem->setToolTip(resultMap["artist_name"].toString()); artistItem->setFont(QFont("微软雅黑", 10)); //专辑 QTableWidgetItem *albumItem = new QTableWidgetItem("《" + resultMap["album_name"].toString() + "》"); albumItem->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); albumItem->setToolTip("《" + resultMap["album_name"].toString() + "》"); albumItem->setFont(QFont("微软雅黑", 10)); //插入播放列表 int currentRows = m_searchList->rowCount();//返回列表中的行数 m_searchList->insertRow(currentRows);//从播放列表中的当前行插入 m_searchList->setCellWidget(currentRows, 0, musicNameCheckBox); m_searchList->setItem(currentRows, 1, artistItem); m_searchList->setItem(currentRows, 2, albumItem); }
QWidget* DSiNo::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { QCheckBox *editor = new QCheckBox( parent ); editor->setText( index.model()->headerData( index.column(), Qt::Horizontal ).toString() ); editor->setTristate( false ); editor->setPalette( option.palette ); editor->setFont( option.font ); editor->setBackgroundRole( QPalette::Background ); return editor; }
void MetronomeWindow::doTick() { if( this->tickIndex >= this->accentChecks.size() ) this->tickIndex = 0; QCheckBox *box = this->accentChecks.at(this->tickIndex); if( box->isChecked() ) this->ticker->tick(Ticker::HighTick); else this->ticker->tick(Ticker::LowTick); int size = this->accentChecks.size(); for( int i=0; i<size; i++ ) { QCheckBox *temp = this->accentChecks.at(i); QFont font(temp->font()); font.setBold(false); temp->setFont( font ); } QFont font(box->font()); font.setBold(true); box->setFont( font ); this->tickIndex++; }
ToolInstance::ToolInstance(QString filename, ToolInformation information, mcrl2::gui::qt::PersistentFileDialog* fileDialog, QWidget *parent) : QWidget(parent), m_filename(filename), m_info(information), m_fileDialog(fileDialog) { m_ui.setupUi(this); connect(this, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor))); connect(&m_process, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(onStateChange(QProcess::ProcessState))); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(onStandardOutput())); connect(&m_process, SIGNAL(readyReadStandardError()), this, SLOT(onStandardError())); connect(m_ui.btnRun, SIGNAL(clicked()), this, SLOT(onRun())); connect(m_ui.btnAbort, SIGNAL(clicked()), this, SLOT(onAbort())); connect(m_ui.btnSave, SIGNAL(clicked()), this, SLOT(onSave())); connect(m_ui.btnClear, SIGNAL(clicked()), m_ui.edtOutput, SLOT(clear())); QFileInfo fileInfo(filename); m_process.setWorkingDirectory(fileInfo.absoluteDir().absolutePath()); m_ui.lblDirectoryValue->setText(fileInfo.absoluteDir().absolutePath()); m_ui.lblFileValue->setText(fileInfo.fileName()); if (m_info.hasOutput()) { QDir dir = fileInfo.absoluteDir(); QString newfile = fileInfo.baseName().append(".%1").arg(m_info.output); int filenr = 0; while(dir.exists(newfile)) { filenr++; newfile = fileInfo.baseName().append("_%1.%2").arg(filenr).arg(m_info.output); } m_pckFileOut = new FilePicker(m_fileDialog, m_ui.pckFileOut); m_ui.pckFileOut->layout()->addWidget(m_pckFileOut); m_pckFileOut->setText(newfile); } else { m_pckFileOut = NULL; m_ui.lblFileOut->setVisible(false); m_ui.pckFileOut->setVisible(false); } if (m_info.hasSecondInput()) { m_pckFileIn = new FilePicker(m_fileDialog, m_ui.pckFileIn, false); m_ui.pckFileIn->layout()->addWidget(m_pckFileIn); } else { m_pckFileIn = NULL; m_ui.lblFileIn->setVisible(false); m_ui.pckFileIn->setVisible(false); } QFormLayout *formLayout = new QFormLayout(); formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); for (int i = 0; i < m_info.options.count(); i++) { ToolOption option = m_info.options.at(i); QWidget *nameOpt = NULL; QCheckBox* cbOpt = NULL; QVBoxLayout *lytOpt = new QVBoxLayout(); if (option.argument.type == EnumArgument) { nameOpt = new QLabel("<b>"+option.nameLong+": </b>"); } else { cbOpt = new QCheckBox(option.nameLong + ": ", this); cbOpt->setChecked(option.standard); QFont font(cbOpt->font()); font.setBold(true); cbOpt->setFont(font); nameOpt = cbOpt; } formLayout->addRow(nameOpt, lytOpt); QLabel *lblOpt = new QLabel(option.description, this); lblOpt->setAlignment(Qt::AlignJustify | Qt::AlignTop); lblOpt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); lblOpt->setWordWrap(true); lytOpt->addWidget(lblOpt); if (!option.hasArgument()) { m_optionValues.append(new OptionValue(option, cbOpt)); } else { switch (option.argument.type) { case StringArgument: case LevelArgument: case IntegerArgument: case RealArgument: case BooleanArgument: { QHBoxLayout *lytArg = new QHBoxLayout(); lytArg->setSpacing(6); QWidget *edtArg = NULL; switch (option.argument.type) { case LevelArgument: { QLineEdit *edtLdt = new QLineEdit("verbose", this); m_optionValues.append(new OptionValue(option, cbOpt, edtLdt)); edtArg = edtLdt; } break; case IntegerArgument: { QSpinBox *edtSpb = new QSpinBox(this); edtSpb->setRange(std::numeric_limits<int>::min(), std::numeric_limits<int>::max()); if (option.argument.optional) { QCheckBox *cbOptional = new QCheckBox(this); lytArg->addWidget(cbOptional); m_optionValues.append(new OptionValue(option, cbOpt, edtSpb, cbOptional)); } else { m_optionValues.append(new OptionValue(option, cbOpt, edtSpb)); } edtArg = edtSpb; } break; case RealArgument: { QDoubleSpinBox *edtSpb = new QDoubleSpinBox(this); edtSpb->setRange(std::numeric_limits<double>::min(), std::numeric_limits<double>::max()); if (option.argument.optional) { QCheckBox *cbOptional = new QCheckBox(this); lytArg->addWidget(cbOptional); m_optionValues.append(new OptionValue(option, cbOpt, edtSpb, cbOptional)); } else { m_optionValues.append(new OptionValue(option, cbOpt, edtSpb)); } edtArg = edtSpb; } break; case BooleanArgument: { QCheckBox *edtChb = new QCheckBox("Yes", this); m_optionValues.append(new OptionValue(option, cbOpt, edtChb)); edtArg = edtChb; } break; case StringArgument: default: { QLineEdit *edtLdt = new QLineEdit(this); m_optionValues.append(new OptionValue(option, cbOpt, edtLdt)); edtArg = edtLdt; } break; } edtArg->setMinimumWidth(300); lytArg->addWidget(edtArg); if (!option.argument.optional && option.argument.type != BooleanArgument) { QLabel *lblReq = new QLabel("*", this); lytArg->addWidget(lblReq); } QSpacerItem *spacer = new QSpacerItem(100, 20, QSizePolicy::Expanding); lytArg->addItem(spacer); lytOpt->addLayout(lytArg); } break; case FileArgument: { QHBoxLayout *lytArg = new QHBoxLayout(); lytArg->setSpacing(6); FilePicker *edtArg = new FilePicker(m_fileDialog, this, false); lytArg->addWidget(edtArg); m_optionValues.append(new OptionValue(option, cbOpt, edtArg)); if (!option.argument.optional) { QLabel *lblReq = new QLabel("*", this); lytArg->addWidget(lblReq); } QSpacerItem *spacer = new QSpacerItem(100, 20, QSizePolicy::Expanding); lytArg->addItem(spacer); lytOpt->addLayout(lytArg); } break; case EnumArgument: { QFormLayout *lytValues = new QFormLayout(); lytValues->setSpacing(6); QButtonGroup *grpValues = new QButtonGroup(this); for (int j = 0; j < option.argument.values.count(); j++) { ToolValue val = option.argument.values.at(j); QRadioButton *rbVal = new QRadioButton(val.nameLong, this); rbVal->setChecked(val.standard); grpValues->addButton(rbVal); QLabel *lblVal = new QLabel(val.description, this); lblVal->setWordWrap(true); lytValues->addRow(rbVal, lblVal); } m_optionValues.append(new OptionValue(option, cbOpt, grpValues)); lytOpt->addLayout(lytValues); } break; default: break; } } } m_ui.scrollWidget->setLayout(formLayout); }
void QtHelpers::GenAdjustWidgetAppearanceToOS(QWidget *rootWidget) { if (rootWidget == NULL) return; QObject *child = NULL; QObjectList Containers; QObject *container = NULL; QStringList DoNotAffect; // Make an exception list (Objects not to be affected) DoNotAffect.append("aboutTitleLabel"); // about Dialog DoNotAffect.append("aboutVersionLabel"); // about Dialog DoNotAffect.append("aboutCopyrightLabel"); // about Dialog DoNotAffect.append("aboutUrlLabel"); // about Dialog DoNotAffect.append("aboutLicenseLabel"); // about Dialog // Set sizes according to OS: #ifdef __APPLE__ int ButtonHeight = 35; int cmbxHeight = 30; QFont cntrlFont("Myriad Pro", 14); QFont txtFont("Myriad Pro", 14); #elif _WIN32 // Win XP/7 int ButtonHeight = 24; int cmbxHeight = 20; QFont cntrlFont("MS Shell Dlg 2", 8); QFont txtFont("MS Shell Dlg 2", 8); #else int ButtonHeight = 24; int cmbxHeight = 24; QFont cntrlFont("Ubuntu Condensed", 10); QFont txtFont("Ubuntu", 10); #endif // Append root to containers Containers.append(rootWidget); while (!Containers.isEmpty()) { container = Containers.takeFirst(); if (container != NULL) { for (int ChIdx=0; ChIdx < container->children().size(); ChIdx++) { child = container->children()[ChIdx]; if (!child->isWidgetType() || DoNotAffect.contains(child->objectName())) continue; // Append containers to Stack for recursion if (child->children().size() > 0) Containers.append(child); else { // Cast child object to button and label // (if the object is not of the correct type, it will be NULL) QPushButton *button = qobject_cast<QPushButton *>(child); QLabel *label = qobject_cast<QLabel *>(child); QComboBox *cmbx = qobject_cast<QComboBox *>(child); QLineEdit *ln = qobject_cast<QLineEdit *>(child); QTreeWidget *tree = qobject_cast<QTreeWidget *>(child); QPlainTextEdit *plain = qobject_cast<QPlainTextEdit *>(child); QCheckBox *check = qobject_cast<QCheckBox *>(child); if (button != NULL) { button->setMinimumHeight(ButtonHeight); // Win button->setMaximumHeight(ButtonHeight); // Win button->setFont(cntrlFont); } else if (cmbx != NULL) { cmbx->setFont(cntrlFont); cmbx->setMaximumHeight(cmbxHeight); } else if (label != NULL) label->setFont(txtFont); else if (ln != NULL) ln->setFont(txtFont); else if (tree != NULL) { tree->header()->setFont(txtFont); } else if (plain != NULL) plain->setFont(txtFont); else if (check != NULL) check->setFont(txtFont); } } } } }
FindDialog::FindDialog(EditorPane *parent, bool replace, bool hasSelection) : QDialog(parent), m_parent(parent), m_searching(false), m_modifiable(true) { QStyle *style = new QCleanlooksStyle(); setFont(QFont("arial", 10)); const QFont font("arial", 9); // assure EditorPane is notified upon invocation of find/replace // connect(this, SIGNAL(accepted()), m_parent, SLOT(findDialogInvoked())); setWindowTitle(tr("Find")); QGridLayout *mainLayout = new QGridLayout(); QVBoxLayout *layout = new QVBoxLayout(); // Find section QGroupBox *box = new QGroupBox(tr("Find"), this); box->setStyle(style); QLabel *label = new QLabel(tr("Text to find:"), this); m_lineEdit = new QLineEdit(this); connect(m_lineEdit, SIGNAL(returnPressed()), this, SLOT(accept())); m_regularExpression = new QCheckBox(tr("Regular e&xpression"), this); m_regularExpression->setStyle(style); m_regularExpression->setFont(font); layout->addWidget(label); layout->addWidget(m_lineEdit); layout->addWidget(m_regularExpression); layout->addStretch(1); box->setLayout(layout); mainLayout->addWidget(box, 0, 0, 1, 3); // Replace section m_replaceWidget = new ReplaceWidget(this, style); m_replaceWidget->setChecked(replace); connect(m_replaceWidget, SIGNAL(toggled(bool)), this, SLOT(updateReplace(bool))); mainLayout->addWidget(m_replaceWidget, 1, 0, 1, 3); // Options section QGridLayout *l = new QGridLayout(); box = new QGroupBox(tr("Options"), this); box->setStyle(style); QCheckBox *b = new QCheckBox(tr("C&ase sensitive"), this); m_caseSensitive = b; b->setStyle(style); b->setFont(font); l->addWidget(b, 0, 0); b = new QCheckBox(tr("&Whole words only"), this); m_wholeWordsOnly = b; b->setStyle(style); b->setFont(font); l->addWidget(b, 1, 0); l->setColumnMinimumWidth(0, b->sizeHint().width() + 10); // hack cause this layout manager apparently has trouble w/ multiple styles b = new QCheckBox(tr("From c&ursor"), this); m_fromCursor = b; b->setStyle(style); b->setFont(font); l->addWidget(b, 2, 0); b = new QCheckBox(tr("Find &backwards"), this); m_findBackwards = b; b->setStyle(style); b->setFont(font); l->addWidget(b, 0, 1); b = new QCheckBox(tr("&Search selection"), this); m_searchSelection = b; b->setStyle(style); b->setFont(font); b->setEnabled(hasSelection); l->setColumnMinimumWidth(1, b->sizeHint().width() + 10); // hack cause this layout manager apparently has trouble w/ multiple styles connect(m_parent, SIGNAL(copyAvailabile(bool)), b, SLOT(setEnabled(bool))); l->addWidget(b, 1, 1); /* b = new QCheckBox(tr("&Prompt on replace"), this); m_promptOnReplace = b; b->setStyle(style); b->setEnabled(replace); connect(m_replaceWidget, SIGNAL(toggled(bool)), b, SLOT(setEnabled(bool))); l->addWidget(b, 2, 1);*/ box->setLayout(l); mainLayout->addWidget(box, 2, 0, 1, 3); // Bottom buttons (invoke, cancel, replaceAll) m_invoked = new QPushButton((replace ? "&Replace" : "&Find")); m_invoked->setAutoDefault(true); m_invoked->setStyle(style); connect(m_invoked, SIGNAL(clicked()), this, SLOT(accept())); mainLayout->addWidget(m_invoked, 3, 0);//, Qt::AlignRight); m_cancel = new QPushButton("&Cancel"); m_cancel->setAutoDefault(false); m_cancel->setStyle(style); connect(m_cancel, SIGNAL(clicked()), this, SLOT(reject())); mainLayout->addWidget(m_cancel, 3, 2);//, Qt::AlignRight); m_replaceAll = new QPushButton("Replace &All"); m_replaceAll->setAutoDefault(false); m_replaceAll->setStyle(style); connect(m_replaceAll, SIGNAL(clicked()), this, SLOT(replaceAll())); mainLayout->addWidget(m_replaceAll, 3, 1); mainLayout->setSizeConstraint(QLayout::SetFixedSize); updateReplace(replace); setLayout(mainLayout); setModal(false); }