Results 1 to 7 of 7

Thread: How to add data into the QTableWidget

  1. #1
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    68
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to add data into the QTableWidget

    Hi All,
    I have a QTableWidget which has 200 rows and 4 columns. The user will input the data from 4 QlineEdits in a different dialog. These 4 QlineEdit Values has to be displayed in the QTableWidget. How to resolve this issue. any snippts will be greatful.
    Thanks & Regards
    Sandeep G.R.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to add data into the QTableWidget

    the simplest way. it is to pass pointer to QTableWidget into your dialog.
    Qt Code:
    1. Dialog::Dialog(QTableWidget *table, QWidget *parent)
    2. : Dialog(parent), m_table(table)
    3. {
    4. ....
    5. }
    6.  
    7. void Dialog::saveDataIntoTable()
    8. {
    9. if (!m_table)
    10. return;
    11.  
    12. const int currentRow = m_table->rowCount();
    13. m_table->setRowCount(currentRow + 1);
    14.  
    15. m_table->setItem(currentRow, 0, new QTableWidgetItem(m_lineEdit1->text()));
    16. m_table->setItem(currentRow, 1, new QTableWidgetItem(m_lineEdit2->text()));
    17. ...
    18. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 2 users say thank you to spirit for this useful post:

    ahmetturan (5th July 2011), ljuhrich (1st June 2013)

  4. #3
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add data into the QTableWidget

    another way is to create getters in your dialog and use them to get values after dialog.exec() returns.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  5. #4
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    68
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to add data into the QTableWidget

    Thanks for the reply my intension is to make application similar to addressbook example in Qt but instead of Listview i need to use TableWidget..

    And here is my code snippet

    Qt Code:
    1. ToolForm::ToolForm( QDialog *parent, Qt::WindowFlags f)
    2. : QDialog( parent, f),
    3. {
    4. setupViews();
    5. setupUi(this);
    6. }
    7.  
    8. ToolForm::~ToolForm()
    9. {
    10. }
    11.  
    12. void ToolForm::setupViews()
    13. {
    14. QTableWidget *tooltableWidget = new QTableWidget(200, 4, this);
    15. tooltableWidget->setHorizontalHeaderLabels(QStringList() << tr("TOOL NUMBER")
    16. << tr("DIAMETER")
    17. << tr("LENGTH")
    18. << tr("UNITS"));
    19. tooltableWidget->verticalHeader()->setVisible(false);
    20. tooltableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    21. tooltableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    22. tooltableWidget->setShowGrid(false);
    23. tooltableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    24. tooltableWidget->setGeometry(QRect(0, 100, 781, 281));
    25. tooltableWidget->horizontalHeader()->resizeSection(1, 250);
    26. tooltableWidget->horizontalHeader()->resizeSection(2, 250);
    27. tooltableWidget->horizontalHeader()->resizeSection(3, 180);
    28. }
    29.  
    30. void ToolForm::add_tool()
    31. {
    32. ToolAddDialog tooladddialog;
    33.  
    34. if( tooladddialog.exec())
    35. {
    36.  
    37. QTableWidget *tooltableWidget = new QTableWidget;
    38. QString str = tooladddialog.toolgetValues();
    39. QStringList fields = str.split(" ");
    40. //now i need to display the values from tooladddialog. to TableWidget
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 

    how to proceed with this..
    Thanks & Regards
    Sandeep G.R.

  6. #5
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    68
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to add data into the QTableWidget

    Hi All,

    I tried with the method which was replied by spirit but its not working can anyone tell me how to resolve this issue.
    Thanks & Regards
    Sandeep G.R.

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to add data into the QTableWidget

    Quote Originally Posted by grsandeep85 View Post
    I tried with the method which was replied by spirit but its not working can anyone tell me how to resolve this issue.
    Then you probably have an error in your source code. Show us your relevant code, then we can help.

  8. #7
    Join Date
    Nov 2013
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to add data into the QTableWidget

    Could some one tell me how to do the same using JavaScript? Really appreciated.

Similar Threads

  1. data rate transfer is decreasing in TCP connection
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 16:15
  2. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  3. Replies: 4
    Last Post: 19th October 2007, 19:47
  4. reading and writing data from a QTableWidget
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2007, 20:51
  5. Obtaining data from QTableWidget
    By therealjag in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 07:42

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.