giblit
23rd March 2013, 03:49
So I figured out how I can put the text from the ListWidget into the textEdit but what I would like to do is after I select the item I then have to press a QPushButton before it will display the text into the textEdit box I tried using this:
listWidget->addItem(new QListWidgetItem("Hello"));
listWidget->addItem(new QListWidgetItem("World"));
listWidget->addItem(new QListWidgetItem("Andrew"));
listWidget->setSelectionMode(QAbstractItemView::MultiSelection );
QModelIndex modelIndex = listWidget->rootIndex();
listWidget->setCurrentIndex(modelIndex);
textEdit->setReadOnly(true);
connect(listWidget,SIGNAL(itemActivated(QListWidge tItem*)),
this,SLOT(listWidgetItemDoubleClicked(QListWidgetI tem*)));
connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(listWidgetItemClicked(QListWidgetItem*)));
connect(pushButton,SIGNAL(clicked()),
this,SLOT(button_pressed()));
}
void ListWidgetDialog::listWidgetItemClicked(QListWidge tItem *item)
{
if(!textEdit->document()->isEmpty()){
QTextCursor c = textEdit->textCursor();
textEdit->setTextCursor(c);
c.beginEditBlock();
textEdit->insertPlainText(", "+item->text());
c.endEditBlock();
}
if(textEdit->document()->isEmpty()){
QTextCursor c = textEdit->textCursor();
c.beginEditBlock();
textEdit->insertPlainText(item->text());
c.endEditBlock();
}
}
void ListWidgetDialog::button_pressed(){
void listWidgetItemClicked(QListWidgetItem*);
textEdit->insertPlainText("HELLO I HAVE BEEN PRESSED");
}
but it shows the items when I press them on the ListWidget. and then Shows the message "HELLO I HAVE BEEN PRESSED" when I press the button. I want it to display nothing when I press on the ListWidget, but when I press on the ListWidget then the Button it to display the item then the "hello" message.
listWidget->addItem(new QListWidgetItem("Hello"));
listWidget->addItem(new QListWidgetItem("World"));
listWidget->addItem(new QListWidgetItem("Andrew"));
listWidget->setSelectionMode(QAbstractItemView::MultiSelection );
QModelIndex modelIndex = listWidget->rootIndex();
listWidget->setCurrentIndex(modelIndex);
textEdit->setReadOnly(true);
connect(listWidget,SIGNAL(itemActivated(QListWidge tItem*)),
this,SLOT(listWidgetItemDoubleClicked(QListWidgetI tem*)));
connect(listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(listWidgetItemClicked(QListWidgetItem*)));
connect(pushButton,SIGNAL(clicked()),
this,SLOT(button_pressed()));
}
void ListWidgetDialog::listWidgetItemClicked(QListWidge tItem *item)
{
if(!textEdit->document()->isEmpty()){
QTextCursor c = textEdit->textCursor();
textEdit->setTextCursor(c);
c.beginEditBlock();
textEdit->insertPlainText(", "+item->text());
c.endEditBlock();
}
if(textEdit->document()->isEmpty()){
QTextCursor c = textEdit->textCursor();
c.beginEditBlock();
textEdit->insertPlainText(item->text());
c.endEditBlock();
}
}
void ListWidgetDialog::button_pressed(){
void listWidgetItemClicked(QListWidgetItem*);
textEdit->insertPlainText("HELLO I HAVE BEEN PRESSED");
}
but it shows the items when I press them on the ListWidget. and then Shows the message "HELLO I HAVE BEEN PRESSED" when I press the button. I want it to display nothing when I press on the ListWidget, but when I press on the ListWidget then the Button it to display the item then the "hello" message.