Results 1 to 16 of 16

Thread: need get data from selected row from QTableWidget?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: need get data from selected row from QTableWidget?

    @squidge - I agree, model / view is much more appropriate for this (and for most other cases where there is a data collection behind a table, IMO).

    @fatecasino: However, if you really want to use a QTableWidget instead of a QTableView and model:

    1 - you need to create a connection from the QTableWidget's cellClicked() signal to a slot so you know -which- combobox is being edited.

    2 - you need to connect each combobox's currentIndexChanged() signal to a slot so you can tell when the user has made a new selection.

    3 - the combination of these first two signals will tell you (a) which combox box is in use and (b) what selection the user made.

    4 - when the user clicks the Add button, you can do one of the following:

    (a) Read each cell in the current row and retrieve either its text (if it is an ordinary QTableWidgetItem that-you- have created and put there) or retrieve the widget (using cellWidget()) and then use that pointer to read the selected text.

    (b) Store the row information somewhere in your application external to the table, and update it in response to combobox currentIndexChanged () or table widget itemChanged() signals. Use this to populate the new row in the table.

    But as squidge suggested, you're doing this the hard way. Read up on model / view (not just the class documentation, but read the tutorial stuff too).

  2. The following user says thank you to d_stranz for this useful post:

    fatecasino (15th February 2011)

  3. #2
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: need get data from selected row from QTableWidget?

    thanks to both of you!
    The last few hours I have been studying this famous article:
    http://doc.trolltech.com/4.7.old/mod...ogramming.html

    It looks very analytic and well-written, I have understood the theory part, BUT when I want to start writing a simple example I get totally lost.There are so many different things to arrange. I will give it 2-3 more days of study, I think it 's a very important concept.

Similar Threads

  1. Border around selected cell in qtablewidget...
    By pyqt123 in forum Qt Programming
    Replies: 4
    Last Post: 16th July 2012, 13:55
  2. Selected Rows moveUp/moveDown in QTableWidget
    By imagineryhead in forum Qt Programming
    Replies: 12
    Last Post: 14th September 2010, 15:01
  3. QTableView only showing data when row selected
    By Banjo in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2009, 05:34
  4. Replies: 5
    Last Post: 2nd April 2007, 08:57
  5. Replies: 5
    Last Post: 27th May 2006, 13:44

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
  •  
Qt is a trademark of The Qt Company.