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
Forum Updated to NodeBB v4.3 + New Features

Appending text to PlainTextedit using combo boxes and buttons

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.2k Views 2 Watching
  • 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.
  • J Offline
    J Offline
    joshuagahan
    wrote on 20 Jun 2016, 21:41 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}"
    }
    }

    J 1 Reply Last reply 20 Jun 2016, 22:36
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 20 Jun 2016, 21:57 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) );
          }
      }
      
      J 1 Reply Last reply 20 Jun 2016, 22:00
      1
      • ? A Former User
        20 Jun 2016, 21:57

        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) );
            }
        }
        
        J Offline
        J Offline
        joshuagahan
        wrote on 20 Jun 2016, 22:00 last edited by
        #3

        @Wieland thank you so much!

        1 Reply Last reply
        0
        • J joshuagahan
          20 Jun 2016, 21:41

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

          J Offline
          J Offline
          joshuagahan
          wrote on 20 Jun 2016, 22:36 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
          • J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 21 Jun 2016, 04:27 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

            J 1 Reply Last reply 21 Jun 2016, 07:19
            0
            • J jsulm
              21 Jun 2016, 04:27

              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?

              J Offline
              J Offline
              joshuagahan
              wrote on 21 Jun 2016, 07:19 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

              2/6

              20 Jun 2016, 21:57

              topic:navigator.unread, 4
              • Login

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