Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Appending text to PlainTextedit using combo boxes and buttons
QtWS25 Last Chance

Appending text to PlainTextedit using combo boxes and buttons

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joshuagahanJ Offline
    joshuagahanJ Offline
    joshuagahan
    wrote on last edited by
    #1

    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}"
    }
    }

    joshuagahanJ 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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) );
          }
      }
      
      joshuagahanJ 1 Reply Last reply
      1
      • ? A Former User

        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) );
            }
        }
        
        joshuagahanJ Offline
        joshuagahanJ Offline
        joshuagahan
        wrote on last edited by
        #3

        @Wieland thank you so much!

        1 Reply Last reply
        0
        • joshuagahanJ joshuagahan

          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}"
          }
          }

          joshuagahanJ Offline
          joshuagahanJ Offline
          joshuagahan
          wrote on last edited by joshuagahan
          #4

          @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) );
          }
          }

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            joshuagahanJ 1 Reply Last reply
            0
            • jsulmJ jsulm

              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?

              joshuagahanJ Offline
              joshuagahanJ Offline
              joshuagahan
              wrote on last edited by
              #6

              @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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved