Example #1
0
QWidget* ComboDelegate::createEditor( QWidget* parent,
									 const QStyleOptionViewItem&,
									 const QModelIndex&) const {

	QComboBox* combo = new QComboBox(parent);
	combo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
	combo->setMinimumHeight(ComboDelegate::MINIMUM_EDITOR_HEIGHT);
	return combo;
}
Example #2
0
// Create new combo widget
QtWidgetObject* AtenTreeGuiDialog::addCombo(TreeGuiWidget* widget, QString label)
{
	QtWidgetObject* qtwo = widgetObjects_.add();
	QComboBox* combo = new QComboBox(this);
	qtwo->set(widget, combo, label);
	// Add items to combo and set current index
	for (int n=0; n<widget->comboItems().count(); ++n) combo->addItem(widget->comboItems().at(n));
	combo->setCurrentIndex(widget->valueI() - 1);
	combo->setEnabled(widget->enabled());
	combo->setVisible(widget->visible());
	combo->setMinimumHeight(WIDGETHEIGHT);
	combo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
	// Connect signal to master slot
	QObject::connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(comboWidget_currentIndexChanged(int)));
	return qtwo;
}
QWidget * MTPageNym_AltLocation::createSingleContactItem(GroupBoxContactItems * pGroupBox, int nComboIndex/*=0*/,
                                                         const QString textValue/*=""*/, const bool bIsPrimary/*=false*/)
{
    QWidget      * pWidgetContactItem = new QWidget;
    // ----------------------------------------------------------
    QComboBox    * pComboType = new QComboBox(pWidgetContactItem);
    QLineEdit    * pLineEditItemValue = new QLineEdit(pWidgetContactItem);
    QPushButton  * pBtnDelete = new QPushButton(tr("Delete"), pWidgetContactItem);
    QRadioButton * pBtnRadio = new QRadioButton(tr("Primary"), pWidgetContactItem);

    pGroupBox->addRadioButton(pBtnRadio);
    // ----------------------------------------------------------
    pComboType->setMinimumWidth(60);
    pComboType->setMinimumHeight(25);
    pComboType->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    pBtnDelete->setMinimumHeight(25);
    pBtnDelete->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    pLineEditItemValue->setMinimumWidth(55);
    pLineEditItemValue->setMinimumHeight(25);
    pLineEditItemValue->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    // ----------------------------------------------------------
    pWidgetContactItem->setProperty("groupbox",          VPtr<GroupBoxContactItems>::asQVariant(pGroupBox));
    pWidgetContactItem->setProperty("combo",             VPtr<QComboBox>::asQVariant(pComboType));
    pWidgetContactItem->setProperty("lineedit",          VPtr<QLineEdit>::asQVariant(pLineEditItemValue));
    pWidgetContactItem->setProperty("deletebtn",         VPtr<QPushButton>::asQVariant(pBtnDelete));
    pWidgetContactItem->setProperty("radiobtn",          VPtr<QRadioButton>::asQVariant(pBtnRadio));
    // ----------------------------------------------------------
    pComboType        ->setProperty("contactitemwidget", VPtr<QWidget>::asQVariant(pWidgetContactItem));
    pLineEditItemValue->setProperty("contactitemwidget", VPtr<QWidget>::asQVariant(pWidgetContactItem));
    pBtnDelete        ->setProperty("contactitemwidget", VPtr<QWidget>::asQVariant(pWidgetContactItem));
    pBtnRadio         ->setProperty("contactitemwidget", VPtr<QWidget>::asQVariant(pWidgetContactItem));
    // ---------------------------------------------------------
//  pBtnDelete->setMinimumWidth(60);
//  pBtnDelete->setProperty("contactSection",     contactSection);
//  pBtnDelete->setProperty("contactSectionType", contactSectionType);
    // ----------------------------------------------------------
    for (QMap<uint32_t, QString>::iterator it_types = pGroupBox->mapTypeNames_.begin();
         it_types != pGroupBox->mapTypeNames_.end();
         ++it_types)
    {
        const uint32_t  & key   = it_types.key();       // section type ID
        const QString   & value = it_types.value();     // section type name

        pComboType->addItem(value, QVariant::fromValue(key));
    }
    // ----------------------------------------------------------
    // We don't set this until here, underneath the above loop.
    // After all, you can't set the combo box to a certain current index
    // if you haven't even populated it yet!
    //
    pBtnRadio->setChecked(bIsPrimary);
    pComboType->setCurrentIndex(nComboIndex);
    pLineEditItemValue->setText(textValue);
    // ----------------------------------------------------------
    QHBoxLayout *layout = new QHBoxLayout(pWidgetContactItem);

    layout->setMargin(0);

    layout->addWidget(pComboType);
    layout->addWidget(pLineEditItemValue);
    layout->addWidget(pBtnRadio);
    layout->addWidget(pBtnDelete);
    // ----------------------------------------------------------
    pWidgetContactItem->setLayout(layout);

    connect(pComboType, SIGNAL(currentIndexChanged(int)), this, SLOT(on_comboBox_currentIndexChanged(int)) );
    connect(pBtnDelete, SIGNAL(clicked()), this, SLOT(on_btnContactItemDelete_clicked()));
    connect(pLineEditItemValue, SIGNAL(textChanged(QString)), this, SLOT(on_lineEditItemValue_textChanged(QString)));
    connect(pBtnRadio, SIGNAL(toggled(bool)), this, SLOT(on_btnPrimary_toggled(bool)));
//  connect(this, SIGNAL(initialNameProfileSetting(QString)), pLineEditItemValue, SIGNAL(textChanged(QString)));
    // ----------------------------------------------------------
//    layout->setStretch(0,  0);
//    layout->setStretch(1, -1);
//    layout->setStretch(2,  0);
    // ----------------------------------------------------------
    return pWidgetContactItem;
}