本文整理汇总了C++中CComboBox::setCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C++ CComboBox::setCurrentItem方法的具体用法?C++ CComboBox::setCurrentItem怎么用?C++ CComboBox::setCurrentItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComboBox
的用法示例。
在下文中一共展示了CComboBox::setCurrentItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addWidget
void JabberSearch::addWidget(JabberAgentInfo *data)
{
QWidget *widget = NULL;
bool bJoin = false;
if (!data->Type.str().isEmpty()){
if (data->Type.str() == "x"){
m_bXData = true;
vector<QWidget*>::iterator it;
for (it = m_widgets.begin(); it != m_widgets.end(); ++it)
if (*it)
delete (*it);
m_widgets.clear();
for (it = m_labels.begin(); it != m_labels.end(); ++it)
if (*it)
delete (*it);
m_labels.clear();
for (it = m_descs.begin(); it != m_descs.end(); ++it)
if (*it)
delete (*it);
m_descs.clear();
m_instruction = QString::null;
}else if (data->Type.str() == "title"){
if (!data->Value.str().isEmpty())
m_title = data->Value.str();
}else if (data->Type.str() == "text-single"){
widget = new QLineEdit(this, data->Field.str());
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
if (!data->Value.str().isEmpty())
static_cast<QLineEdit*>(widget)->setText(data->Value.str());
}else if (data->Type.str() == "text-private"){
widget = new QLineEdit(this, data->Field.str());
static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
if (!data->Value.str().isEmpty())
static_cast<QLineEdit*>(widget)->setText(data->Value.str());
}else if (data->Type.str() == "text-multi"){
widget = new QMultiLineEdit(this, data->Field.str());
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
if (!data->Value.str().isEmpty())
static_cast<QMultiLineEdit*>(widget)->setText(data->Value.str());
}else if (data->Type.str() == "boolean" && !data->Label.str().isEmpty()){
widget = new QCheckBox(data->Label.str(), this, data->Field.str());
if (!data->Value.str().isEmpty() && !data->Value.str().startsWith("0"))
static_cast<QCheckBox*>(widget)->setChecked(true);
data->Label.clear();
bJoin = true;
}else if (data->Type.str() == "fixed"){
if (!data->Value.str().isEmpty()){
QString text = i18(data->Value.str());
text = text.replace(QRegExp(" +"), "\n");
if (m_bFirst){
if (!m_label.isEmpty())
m_label += '\n';
m_label += text;
}else{
QLabel *label = new QLabel(text, this);
label->setAlignment(WordBreak);
widget = label;
bJoin = true;
}
}
}else if (data->Type.str() == "instructions"){
if (!data->Value.str().isEmpty()){
QString text = i18(data->Value.str());
text = text.replace(QRegExp(" +"), "\n");
if (!m_instruction.isEmpty())
m_instruction += '\n';
m_instruction += text;
}
}else if (data->Type.str() == "list-single"){
CComboBox *box = new CComboBox(this, data->Field.str());
int cur = 0;
int n = 0;
for (unsigned i = 0; i < data->nOptions.toULong(); i++){
QString label = get_str(data->OptionLabels, i);
QString val = get_str(data->Options, i);
if (label && val){
box->addItem(i18(label), val);
if (data->Value.str() == val)
cur = n;
n++;
}
}
box->setCurrentItem(cur);
widget = box;
}else if (data->Type.str() == "key"){
if (!data->Value.str().isEmpty())
m_key = data->Value.str();
}else if (data->Type.str() == "password"){
widget = new QLineEdit(this, "password");
static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
data->Label.str() = "Password";
}else if (data->Type.str() == "online"){
widget = new QCheckBox(this, "online");
static_cast<QCheckBox*>(widget)->setText(i18n("Online only"));
bJoin = true;
//.........这里部分代码省略.........
示例2: addWidget
void JabberSearch::addWidget(JabberAgentInfo *data)
{
QWidget *widget = NULL;
bool bJoin = false;
if (data->Type.ptr){
if (!strcmp(data->Type.ptr, "x")){
m_bXData = true;
}else if (!strcmp(data->Type.ptr, "title")){
if (data->Value.ptr && *data->Value.ptr)
m_title = QString::fromUtf8(data->Value.ptr);
}else if (!strcmp(data->Type.ptr, "text-single")){
widget = new QLineEdit(this, data->Field.ptr);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
if (data->Value.ptr && *data->Value.ptr)
static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
}else if (!strcmp(data->Type.ptr, "text-private")){
widget = new QLineEdit(this, data->Field.ptr);
static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
if (data->Value.ptr && *data->Value.ptr)
static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
}else if (!strcmp(data->Type.ptr, "text-multi")){
widget = new QMultiLineEdit(this, data->Field.ptr);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
if (data->Value.ptr && *data->Value.ptr)
static_cast<QMultiLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
}else if (!strcmp(data->Type.ptr, "boolean") && data->Label.ptr){
widget = new QCheckBox(QString::fromUtf8(data->Label.ptr), this, data->Field.ptr);
if (data->Value.ptr && *data->Value.ptr && (*data->Value.ptr != '0'))
static_cast<QCheckBox*>(widget)->setChecked(true);
set_str(&data->Label.ptr, NULL);
bJoin = true;
}else if (!strcmp(data->Type.ptr, "fixed")){
if (data->Value.ptr){
QString text = i18(data->Value.ptr);
text = text.replace(QRegExp(" +"), "\n");
if (m_bFirst){
if (!m_label.isEmpty())
m_label += "\n";
m_label += text;
}else{
QLabel *label = new QLabel(text, this);
label->setAlignment(WordBreak);
widget = label;
bJoin = true;
}
}
}else if (!strcmp(data->Type.ptr, "instructions")){
if (data->Value.ptr){
QString text = i18(data->Value.ptr);
text = text.replace(QRegExp(" +"), "\n");
if (!m_instruction.isEmpty())
m_instruction += "\n";
m_instruction += text;
}
}else if (!strcmp(data->Type.ptr, "list-single")){
CComboBox *box = new CComboBox(this, data->Field.ptr);
int cur = 0;
int n = 0;
for (unsigned i = 0; i < data->nOptions.value; i++){
const char *label = get_str(data->OptionLabels, i);
const char *val = get_str(data->Options, i);
if (label && val){
box->addItem(i18(label), val);
if (data->Value.ptr && !strcmp(data->Value.ptr, val))
cur = n;
n++;
}
}
box->setCurrentItem(cur);
widget = box;
}else if (!strcmp(data->Type.ptr, "key")){
if (data->Value.ptr)
m_key = data->Value.ptr;
}else if (!strcmp(data->Type.ptr, "password")){
widget = new QLineEdit(this, "password");
static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
set_str(&data->Label.ptr, "Password");
}else if (!strcmp(data->Type.ptr, "online")){
widget = new QCheckBox(this, "online");
static_cast<QCheckBox*>(widget)->setText(i18n("Online only"));
bJoin = true;
}else if (!strcmp(data->Type.ptr, "sex")){
CComboBox *box = new CComboBox(this, data->Field.ptr);
box->addItem("", "0");
box->addItem(i18n("Male"), "1");
box->addItem(i18n("Female"), "2");
set_str(&data->Label.ptr, I18N_NOOP("Gender"));
widget = box;
}else{
defFlds *f;
for (f = fields; f->tag; f++)
if (!strcmp(data->Type.ptr, f->tag))
break;
if (f->tag){
widget = new QLineEdit(this, f->tag);
//.........这里部分代码省略.........