Appending text to PlainTextedit using combo boxes and buttons
-
wrote on 20 Jun 2016, 21:41 last edited by
New to QT. I'm writing a program that writes macros for a website I play online. Essentially what I want is a combobox that when I press the pushbutton, reads the current combobox selection and appends a snippet of text into the TextEdit.
using pseudo code:
if pushbutton is clicked():
{
read combo box selection
append comboboxselection(string) to Text edit
}combobox()
{
string sometext
if(combobox selection is "1st cantrip")
{
text = "%{selected|repeating_spell-cantrip_$0_spell}"
}
} -
wrote on 20 Jun 2016, 21:57 last edited by
Hi, and welcome to the Qt forum!
void MainWindow::on_pushButton_clicked() { const auto text = ui->comboBox->currentText(); if (text=="First Item") { ui->textEdit->append( QString("%1 something").arg(text) ); } else if (text=="Second Item") { ui->textEdit->append( QString("%1 something else").arg(text) ); } else { ui->textEdit->append( QString("%1 default").arg(text) ); } }
-
Hi, and welcome to the Qt forum!
void MainWindow::on_pushButton_clicked() { const auto text = ui->comboBox->currentText(); if (text=="First Item") { ui->textEdit->append( QString("%1 something").arg(text) ); } else if (text=="Second Item") { ui->textEdit->append( QString("%1 something else").arg(text) ); } else { ui->textEdit->append( QString("%1 default").arg(text) ); } }
wrote on 20 Jun 2016, 22:00 last edited by@Wieland thank you so much!
-
New to QT. I'm writing a program that writes macros for a website I play online. Essentially what I want is a combobox that when I press the pushbutton, reads the current combobox selection and appends a snippet of text into the TextEdit.
using pseudo code:
if pushbutton is clicked():
{
read combo box selection
append comboboxselection(string) to Text edit
}combobox()
{
string sometext
if(combobox selection is "1st cantrip")
{
text = "%{selected|repeating_spell-cantrip_$0_spell}"
}
}wrote on 20 Jun 2016, 22:36 last edited by joshuagahan@Wieland
Follow on Question: After implementing the code: nothing happened, I went the moc file where
void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
MainWindow *_t = static_cast<MainWindow *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->on_deleteThisComboBox_currentTextChanged((reinterpret_cast< const QString()>(_a[1]))); break;
case 1: _t->on_deletThisPlainTextEdit_destroyed(); break;
case 2:_t->on_deletThisPushButton_clicked(); break;
default: ;
}
}
}in case 2: The text is added to the plaintextbox automatically whenever I change the combobox selection, also clicking the pushbutton has no effect on appending text whatsoever, despite the code being inside the code:
void MainWindow::on_deletThisPushButton_clicked()
{
const auto text = ui->deleteThisComboBox->currentText();
if (text=="1st Cantrip") {
ui->deletThisPlainTextEdit->appendPlainText( QString("something").arg(text) );
} else if (text=="2nd Cantrip") {
ui->deletThisPlainTextEdit->appendPlainText( QString("something else").arg(text) );
} else {
ui->deletThisPlainTextEdit->appendPlainText( QString("default").arg(text) );
}
} -
Sorry, it is not really clear what the problem now is. @Wieland provided you the code you have to put into your slot which is connected to the clicked signal of the button. Did you connect the signal and slot?
-
Sorry, it is not really clear what the problem now is. @Wieland provided you the code you have to put into your slot which is connected to the clicked signal of the button. Did you connect the signal and slot?
wrote on 21 Jun 2016, 07:19 last edited by@jsulm Its been working fine this is solved. I have a project where I experiment in and got a lot of my code messed up. When I tried this code in a fresh project, it worked perfectly. Thanks.
2/6