#include <QtGui/QApplication>
#include <Qt/qglobal.h>
#include <QDialog>
#include <QLabel>
#include <QComboBox>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
{
Q_OBJECT
public:
{
Combo -> setEditable(true);
Combo -> addItem("Original default");
Combo
-> setInsertPolicy
(QComboBox::InsertAtCurrent);
Button -> setDefault(false);
Label -> setText(Combo -> currentText());
Layout->addWidget(Label, 0, 2);
Layout->addWidget(Button, 2, 0);
Layout->addWidget(Combo, 2, 2);
setLayout(Layout);
connect(Button, SIGNAL(clicked(const bool &)),
this, SLOT(addItem(const bool &)));
connect(Combo,
SIGNAL(editTextChanged
(const QString &)),
this,
SLOT(synchroniseText
(const QString &)));
connect(Combo, SIGNAL(currentIndexChanged(int)),
this, SLOT(showSelection(int)));
}
public slots:
void addItem(const bool &checked)
{
Combo -> addItem("New default");
}
void synchroniseText
(const QString &newText
) {
Label -> setText(newText);
}
void showSelection(int newSelection)
{
Label -> setText(Combo -> itemText(newSelection));
}
private:
};
#include "main.moc"
int main(int argc, char *argv[])
{
layout->addWidget(new ComboTest);
dialog.setLayout(layout);
return dialog.exec();
}
#include <QtGui/QApplication>
#include <Qt/qglobal.h>
#include <QDialog>
#include <QLabel>
#include <QComboBox>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
class ComboTest : public QWidget
{
Q_OBJECT
public:
ComboTest(QWidget *parent = 0)
: QWidget(parent)
{
Layout = new QGridLayout;
Label = new QLabel;
Combo = new QComboBox;
Combo -> setEditable(true);
Combo -> addItem("Original default");
Combo -> setInsertPolicy(QComboBox::InsertAtCurrent);
Button = new QPushButton("Add Item");
Button -> setDefault(false);
Label -> setText(Combo -> currentText());
Layout->addWidget(Label, 0, 2);
Layout->addWidget(Button, 2, 0);
Layout->addWidget(Combo, 2, 2);
setLayout(Layout);
connect(Button, SIGNAL(clicked(const bool &)),
this, SLOT(addItem(const bool &)));
connect(Combo, SIGNAL(editTextChanged(const QString &)),
this, SLOT(synchroniseText(const QString &)));
connect(Combo, SIGNAL(currentIndexChanged(int)),
this, SLOT(showSelection(int)));
}
public slots:
void addItem(const bool &checked)
{
Combo -> addItem("New default");
}
void synchroniseText(const QString &newText)
{
Label -> setText(newText);
}
void showSelection(int newSelection)
{
Label -> setText(Combo -> itemText(newSelection));
}
private:
QGridLayout *Layout;
QLabel *Label;
QComboBox *Combo;
QPushButton *Button;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
QVBoxLayout* layout = new QVBoxLayout(&dialog);
layout->addWidget(new ComboTest);
dialog.setLayout(layout);
return dialog.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks