[PySide] QTableWidget update setRowCount through QComboBox

Bruno-Pierre Jobin bpjobin at gmail.com
Fri May 12 22:18:50 CEST 2017


Hi,

I'm sure this is an easy one for you guys. How can I make the QComboBox
drive the amount of rows of the QTableWidget. For example, I want the
amount of rows to reflect the selected index of the comboBox and it needs
to reset itself every time I select a new index.

Thanks!

from PySide.QtGui import *
from PySide.QtCore import *

class Panel(QWidget):
    def __init__(self):
        super(Panel, self).__init__()

        self.combo = QComboBox()
        self.combo.addItems(['1','2','3','4'])
        self.vlayout = QVBoxLayout()
        self.vlayout.addWidget(self.combo)
        self.vlayout.addWidget(self.buildTable(self.combo.currentText()))
        self.setLayout(self.vlayout)

        self.resize(400,200)

        self.combo.currentIndexChanged.connect(lambda:self.buildTable(self.combo.currentText()))

    def buildTable(self, date):

        self.table = QTableWidget()
        self.table.setColumnCount(2)
        print 'set rows : ', int(date)
        self.table.setRowCount(int(date))

        return self.table

def start():
    start.panel = Panel()
    start.panel.show()

start()



-- 
Bruno-Pierre Jobin
www.bpjobin.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20170512/b913d522/attachment.html>


More information about the PySide mailing list