Results 1 to 3 of 3

Thread: PyQt5 - Reading values from a custom QTablewidget cell

  1. #1
    Join Date
    May 2020
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default PyQt5 - Reading values from a custom QTablewidget cell

    My requirement is to get multiple widget values from a cell from a QTableWidget.

    in one of my QTableWidget's coluumn having a QCheckbox, QLineEdit and another QCheckbox. For adding this I am using QHBoxLayout and QVBoxlayout. But while reading the values, how I can read the values from QTableWidget? I can get the widget while using olumnLvlTbl.cellWidget(0,1). But how I can get the values from nested Widgets?

    colmumnLayoutRow=QHBoxLayout()
    colmumnLayout1=QVBoxLayout()
    dsfLblRowCount=QLabel(str(dataC))
    rowCountChkBox = QCheckBox(parent=columnLvlTbl)
    colmumnLayout1.addWidget(dsfLblRowCount)
    colmumnLayout1.addWidget(rowCountChkBox)

    colmumnLayout2=QVBoxLayout()
    dsfLblRowCount2=QLabel("Pass %:")
    rowCountLineEdit2 = QLineEdit(parent=columnLvlTbl)
    rowCountLineEdit2.setMaximumWidth(50)
    rowCountLineEdit2.setValidator(QtGui.QIntValidator (1, 100, self))
    colmumnLayout2.addWidget(dsfLblRowCount2)
    colmumnLayout2.addWidget(rowCountLineEdit2)

    colmumnLayout3=QVBoxLayout()
    dsfLblRowCount3=QLabel("Notification:")
    rowCountChkBox3 = QCheckBox(parent=columnLvlTbl)
    colmumnLayout3.addWidget(dsfLblRowCount3)
    colmumnLayout3.addWidget(rowCountChkBox3)

    cellWidgetRow1 = QWidget()
    cellWidgetRow1.setLayout(colmumnLayout1)
    cellWidgetRow2 = QWidget()
    cellWidgetRow2.setLayout(colmumnLayout2)
    cellWidgetRow3 = QWidget()
    cellWidgetRow3.setLayout(colmumnLayout3)

    colmumnLayoutRow.addWidget(cellWidgetRow1)
    colmumnLayoutRow.addWidget(cellWidgetRow2)
    colmumnLayoutRow.addWidget(cellWidgetRow3)

    Whenever I am trying to do one action, I need to get the values from the QTableWidget.

    Thanks in Advance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,642
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: PyQt5 - Reading values from a custom QTablewidget cell

    In C++ you would create your own QWidget subclass that either provides access method to get at the sub-widget values, or exposes the sub-widgets as public members that can be directly queried from outside. When you access the cell widget you get a generic QWidget pointer that you need to qobject_cast (in C++):
    Qt Code:
    1. MyCustomWidget *mywidget = qobject_cast<MyCustomWidget *>(tableWidget->cellWidget(row, col));
    2. if (mywidget) {
    3. // access the member functions/variables through mywidget
    4. }
    To copy to clipboard, switch view to plain text mode 

    Exactly how this is achieved in Python I am not sure.... it might "Just Work" with the object returned by cellWidget() and some Pythonic type magic.
    Last edited by ChrisW67; 17th May 2020 at 10:59.

  3. #3
    Join Date
    May 2020
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: PyQt5 - Reading values from a custom QTablewidget cell

    Thanks a lot Chris. I tried to print myTable.cellWidget(0,1) and I am getting
    <PyQt5.QtWidgets.QWidget object at 0x0000028F6E58ADC8>.
    I convert the layout to widget then I added to the QTableWidget's cell. So I need to get the layout and then each widget's values from a cell. This columns are auto-generated depends the database entries.

Similar Threads

  1. Replies: 2
    Last Post: 28th July 2019, 21:11
  2. Replies: 3
    Last Post: 9th November 2012, 18:55
  3. Replies: 1
    Last Post: 1st June 2011, 13:02
  4. pyqt4 reading values from rows of QTableWidget
    By stephen76 in forum Newbie
    Replies: 2
    Last Post: 10th January 2011, 09:55
  5. Replies: 1
    Last Post: 7th December 2009, 18:56

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.