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. How can achieve this in Qtablewidget?
Forum Updated to NodeBB v4.3 + New Features

How can achieve this in Qtablewidget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 995 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 Offline
    A Offline
    aabdn
    wrote on last edited by
    #1

    Hi!
    I am stuck and don't know how to get this operation with Qtablewiget, I have a Qtablewidget which displays data in three columns (data is displayed on cells containing QlindEdit). At start when Qtablewidget appear, I want the very first cell (with QlineEdit) should get focus and then I can use downarrow key to move to every column cell containing QlineEdit. My QTablewidget has 10 rows and 3 columns, everycell in columns contain QlineEdit widget. I want when the focus reach to last cell of column via downarrow key, it should move to first cell of second column in tablewidget. I don't know to to achieve this.

    Can anyone tell me the solution or share any example related to the solution as reference, I will be very helpful for me. I have shared screen shots of my table and the table I want to create like.

    Thank you in advance!

    my code:
    {
    ui->setupUi(this);

    col = 0;
    row = 0;
    
    
        ui->tableWidget->setColumnWidth(0, 107);
        ui->tableWidget->setColumnWidth(1, 200);
        ui->tableWidget->setColumnWidth(2, 107);
        ui->tableWidget->setColumnWidth(3, 200);
        ui->tableWidget->setColumnWidth(4, 107);
        ui->tableWidget->setColumnWidth(5, 200);
    
        for(row=0; row < 10; row++)
        {
        ui->tableWidget->setRowHeight(row, 40);
        }
    
        for(row=0; row<10; row++)
        {
            for(col = 0; col<6; col++)
            {
            if(col==1)
              {ui->tableWidget->setCellWidget(row, col, new QLineEdit());}
            if(col==3)
              {ui->tableWidget->setCellWidget(row, col, new QLineEdit());}
            if(col==5)
              {ui->tableWidget->setCellWidget(row, col, new QLineEdit());}
            }
        }
    
    
        ui->tableWidget->setFocus();
        ui->tableWidget->setCurrentCell(0,1);
    

    // if (col==1 && row==9)
    // {
    // ui->tableWidget->setCurrentCell(0,3);
    // ui->tableWidget->setFocus();
    // }

    }I want to create table like this.png

    my table.png

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Since you are covering your table view with widgets, you will have to use an event filter to capture the keys of interest and move the focus around.

      That said, why do you need that many QLineEdit ?
      Can't you use a custom edit trigger to fulfill your needs ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Since you are covering your table view with widgets, you will have to use an event filter to capture the keys of interest and move the focus around.

        That said, why do you need that many QLineEdit ?
        Can't you use a custom edit trigger to fulfill your needs ?

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

        @SGaist Thank you for your suggestion, now i am trying event filter , let see if it works. Everycolumn cell have data in edit, which is editable that is why i am using QLine Edit in every cell in column.

        Here is what i am trying to do now, hope it will work:
        dece4b81-8214-4248-90bd-2b6d6353d7f0-1657330950832.png

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The thing is: the QTableView already has editing support so putting QLineEdits everywhere is not necessary.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          1
          • SGaistS SGaist

            The thing is: the QTableView already has editing support so putting QLineEdits everywhere is not necessary.

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

            @SGaist You are right, but this time I am trying to move my focus on first cell of column third, as the focus reached at last cell of column first using downarrow key, it (focus) should move to first cell of third column. until now I am unable to achieved it.

            JonBJ 1 Reply Last reply
            0
            • A aabdn

              @SGaist You are right, but this time I am trying to move my focus on first cell of column third, as the focus reached at last cell of column first using downarrow key, it (focus) should move to first cell of third column. until now I am unable to achieved it.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @aabdn
              Use focusNextChild() repeatedly if you have to, or find the widget and call focus() on it.

              You seem to acknowledge what @SGaist has said about not needing all these line edits, yet have not acted on it by removing them all.

              A 1 Reply Last reply
              0
              • JonBJ JonB

                @aabdn
                Use focusNextChild() repeatedly if you have to, or find the widget and call focus() on it.

                You seem to acknowledge what @SGaist has said about not needing all these line edits, yet have not acted on it by removing them all.

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

                @JonB I already have removed QlineEdits from my table as @SGaist suggested, but forget to mention in reply. I am modifying my code using either focusNextChild() or point focus on specific widget. Thank you for helping me out @SGaist @JonB .

                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