Results 1 to 2 of 2

Thread: QTablewidget does not work...

  1. #1
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb QTablewidget does not work...

    Hello guys.

    I am trying to insert data into a QTablewidget and one of the line is blank and the other data wrong (swapped), the code is below.
    Could someone tell me where I'm going wrong?

    Qt Code:
    1. int vnumRow=0;
    2.  
    3. ui->GrdAdvogados->setRowCount(0);
    4.  
    5. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    6. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    7.  
    8. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Roberval da Costa"));
    9. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("777.555.222-88"));
    10. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("3.222.555"));
    11. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    12. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("3.456-PE"));
    13. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.3456"));
    14.  
    15.  
    16. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    17. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    18.  
    19. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Paulo Roberto Rego"));
    20. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("666.555.333-77"));
    21. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("4.111.444"));
    22. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    23. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("1.999-PE"));
    24. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.3333"));
    25.  
    26.  
    27. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    28. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    29.  
    30. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Lucas Toreto"));
    31. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("444.333.888-79"));
    32. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("5.777.888"));
    33. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    34. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("555.000-PE"));
    35. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.1122"));
    36.  
    37.  
    38. //ui->GrdAdvogados->setRowCount(0);
    39. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    40. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    41.  
    42. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Rafaela Butico"));
    43. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("111.222.333-00"));
    44. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("0.444.111"));
    45. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    46. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("5.111-PE"));
    47. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.1111"));
    48.  
    49. // ORDENAR GRID OCORRENCIAS PELA COLUNA PAGINAS (Qt::AscendingOrder)
    50. ui->GrdAdvogados->sortByColumn(0,Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 

    Follow image:

    Erro QTablewidget.jpg

    Thanks in advance

  2. #2
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Wink Re: [SOLVED] QTablewidget does not work...

    Hello everyone.

    Searching the Internet I found the following code and I decided to test, even though I did not see any relation.
    And would you believe it, it worked !!!

    Qt Code:
    1. int vnumRow=0;
    2.  
    3. ui->GrdAdvogados->setRowCount(0);
    4. ui->GrdAdvogados->setSortingEnabled(false); // I Added this code.
    5.  
    6. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    7. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    8.  
    9. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Roberval da Costa"));
    10. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("777.555.222-88"));
    11. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("3.222.555"));
    12. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    13. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("3.456-PE"));
    14. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.3456"));
    15.  
    16. ui->GrdAdvogados->item(vnumRow,1)->setTextAlignment(Qt::AlignCenter);
    17. ui->GrdAdvogados->item(vnumRow,2)->setTextAlignment(Qt::AlignCenter);
    18. ui->GrdAdvogados->item(vnumRow,3)->setTextAlignment(Qt::AlignCenter);
    19. ui->GrdAdvogados->item(vnumRow,5)->setTextAlignment(Qt::AlignCenter);
    20.  
    21.  
    22. ui->GrdAdvogados->insertRow(ui->GrdAdvogados->rowCount());
    23. vnumRow = (ui->GrdAdvogados->rowCount() - 1);
    24.  
    25. ui->GrdAdvogados->setItem(vnumRow, 0, new QTableWidgetItem("Paulo Roberto Rego"));
    26. ui->GrdAdvogados->setItem(vnumRow, 1, new QTableWidgetItem("666.555.333-77"));
    27. ui->GrdAdvogados->setItem(vnumRow, 2, new QTableWidgetItem("4.111.444"));
    28. ui->GrdAdvogados->setItem(vnumRow, 3, new QTableWidgetItem("SDS"));
    29. ui->GrdAdvogados->setItem(vnumRow, 4, new QTableWidgetItem("1.999-PE"));
    30. ui->GrdAdvogados->setItem(vnumRow, 5, new QTableWidgetItem("(81) 3421.3333"));
    31.  
    32. more code .....
    33.  
    34. // ORDENAR GRID OCORRENCIAS PELA COLUNA PAGINAS (Qt::AscendingOrder)
    35. ui->GrdAdvogados->setSortingEnabled(true);
    36. ui->GrdAdvogados->sortByColumn(0,Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 

    Can anyone with more experience explain this?

    Thanks in advance.
    Last edited by marcos.miranda; 4th May 2018 at 14:58. Reason: updated contents

Similar Threads

  1. Replies: 0
    Last Post: 10th April 2015, 14:05
  2. Why the signal "dataChanged" by QTableWidget not work?
    By Tao Clark in forum Qt Programming
    Replies: 1
    Last Post: 20th August 2011, 17:16
  3. Replies: 0
    Last Post: 12th July 2011, 08:20
  4. Replies: 1
    Last Post: 6th January 2011, 04:19
  5. Replies: 12
    Last Post: 28th April 2007, 20:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.