Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. getText QLineEdit in tableWidget
Qt 6.12 LTS is out! See what's new in the release blog

getText QLineEdit in tableWidget

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.9k Views 1 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.
  • A aim0d

    Hi!
    I've been created a table with tableWidget and I also insert QLineEdit in every cell.
    But now I need to retrive the text written in the QLineEdits.
    Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?

    This is how my table is implemanted (with 2columns added via parametri.ui):

    Parametri::Parametri(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Parametri)
    {
        ui->setupUi(this);
        setWindowTitle("Parametri");
    
        for(int row=0;row<=21;row++){    
               val = new QLineEdit(this);        
               ui->tableWidget->setCellWidget(row,0,val);    
               val->setAlignment(Qt::AlignCenter);    
               val->setText("8.00");
            }
    }
    

    Thanks for anyone who can help me

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @aim0d What is wrong with https://doc.qt.io/qt-6/qtablewidget.html#cellWidget and https://doc.qt.io/qt-6/qlineedit.html#text-prop ?

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

    A 1 Reply Last reply
    0
    • jsulmJ jsulm

      @aim0d What is wrong with https://doc.qt.io/qt-6/qtablewidget.html#cellWidget and https://doc.qt.io/qt-6/qlineedit.html#text-prop ?

      A Offline
      A Offline
      aim0d
      wrote on last edited by
      #3

      @jsulm Nothing is wrong with them.
      I just start learning QT, sorry if I dont know every function.
      Thnks.

      jsulmJ 1 Reply Last reply
      0
      • A aim0d

        @jsulm Nothing is wrong with them.
        I just start learning QT, sorry if I dont know every function.
        Thnks.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @aim0d said in getText QLineEdit in tableWidget:

        sorry if I dont know every function

        It is fine to not to know every function, but you can easilly find these two functions in the documentation.
        Usually, if there is a setSomething() method there is also a something() method.

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

        A 1 Reply Last reply
        0
        • jsulmJ jsulm

          @aim0d said in getText QLineEdit in tableWidget:

          sorry if I dont know every function

          It is fine to not to know every function, but you can easilly find these two functions in the documentation.
          Usually, if there is a setSomething() method there is also a something() method.

          A Offline
          A Offline
          aim0d
          wrote on last edited by aim0d
          #5

          @jsulm I've tried with the CellWidget, like this:

           qDebug() << ui->tableWidget->cellWidget(3,0);
          

          Just to see the first output. And this is what it's showing in the terminal QLineEdit(0x58e6f30)

          But I'm not understanding how to show the text inside the QLineEdit.

          jsulmJ 1 Reply Last reply
          0
          • A aim0d

            @jsulm I've tried with the CellWidget, like this:

             qDebug() << ui->tableWidget->cellWidget(3,0);
            

            Just to see the first output. And this is what it's showing in the terminal QLineEdit(0x58e6f30)

            But I'm not understanding how to show the text inside the QLineEdit.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @aim0d said in getText QLineEdit in tableWidget:

            But I'm not understanding how to show the text inside the QLineEdit.

            That was the second link I gave you: https://doc.qt.io/qt-6/qlineedit.html#text-prop
            Of course you will need to cast the pointer returned by cellWidget to QLineEdit*.

            QWidget(0x0) - looks like there is no widget set in 1,2? And if I look at your loop you only have one column, not 3...

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

            A 1 Reply Last reply
            0
            • jsulmJ jsulm

              @aim0d said in getText QLineEdit in tableWidget:

              But I'm not understanding how to show the text inside the QLineEdit.

              That was the second link I gave you: https://doc.qt.io/qt-6/qlineedit.html#text-prop
              Of course you will need to cast the pointer returned by cellWidget to QLineEdit*.

              QWidget(0x0) - looks like there is no widget set in 1,2? And if I look at your loop you only have one column, not 3...

              A Offline
              A Offline
              aim0d
              wrote on last edited by
              #7

              @jsulm Yeah, I edited because I was catching some try I did in the mainWindow.
              I tried with the second link u sent me but having trouble (thanks to my being noob).
              now i was trying with this qDebug() << val->displayText();
              But as expected, it shows every text of every QLineEdit.

              Of course you will need to cast the pointer returned by cellWidget to QLineEdit*

              That I have to look how to do it

              Thks 4 your help

              JonBJ 1 Reply Last reply
              0
              • A aim0d

                @jsulm Yeah, I edited because I was catching some try I did in the mainWindow.
                I tried with the second link u sent me but having trouble (thanks to my being noob).
                now i was trying with this qDebug() << val->displayText();
                But as expected, it shows every text of every QLineEdit.

                Of course you will need to cast the pointer returned by cellWidget to QLineEdit*

                That I have to look how to do it

                Thks 4 your help

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #8

                @aim0d said in getText QLineEdit in tableWidget:

                But as expected, it shows every text of every QLineEdit.

                Is this not what you want/what do you want?

                Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?

                If this is what you mean, then only look at "the second cell of the first row", not every cell?

                A 1 Reply Last reply
                0
                • JonBJ JonB

                  @aim0d said in getText QLineEdit in tableWidget:

                  But as expected, it shows every text of every QLineEdit.

                  Is this not what you want/what do you want?

                  Like if someone write in the second cell of the first row, how can I retrive the value of that QLineEdit?

                  If this is what you mean, then only look at "the second cell of the first row", not every cell?

                  A Offline
                  A Offline
                  aim0d
                  wrote on last edited by aim0d
                  #9

                  @JonB

                  Is this not what you want/what do you want?

                  No, I would like to have for a single cell

                  If this is what you mean, then only look at "the second cell of the first row", not every cell?

                  That's what I'm not understanding how to do it and asking
                  How do I focus just one cell and print the text, not the Widget?

                  JonBJ 1 Reply Last reply
                  0
                  • A aim0d

                    @JonB

                    Is this not what you want/what do you want?

                    No, I would like to have for a single cell

                    If this is what you mean, then only look at "the second cell of the first row", not every cell?

                    That's what I'm not understanding how to do it and asking
                    How do I focus just one cell and print the text, not the Widget?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #10

                    @aim0d
                    Well if you only want to know about one cell specify its row, column cellWidget(row, column) instead of going through some loop!

                    QTextEdit *textEdit = qobject_cast<QTextWidget *>(ui->tableWidget->cellWidget(row, column));
                    if (textEdit)
                        qDebug() << textEdit->text();
                    
                    A 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @aim0d
                      Well if you only want to know about one cell specify its row, column cellWidget(row, column) instead of going through some loop!

                      QTextEdit *textEdit = qobject_cast<QTextWidget *>(ui->tableWidget->cellWidget(row, column));
                      if (textEdit)
                          qDebug() << textEdit->text();
                      
                      A Offline
                      A Offline
                      aim0d
                      wrote on last edited by
                      #11

                      @JonB thanks it workedd!

                      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
                      • Unsolved