-------- Weitergeleitete Nachricht --------
Betreff: Re: [Eric] PyQt-Slot for QtWidget (QComboBox) created during runtime
Datum:  Sun, 23 Sep 2018 23:30:33 +0200
Von:    GM <[email protected]>
An:     Christos Sevastiadis <[email protected]>



Christos,

thanks ... works in the same way and there's no need for an own class, I just have a problem with the rownumber.

If users add more than one line, there will exist 2 or more Comboboxes. Each of them will return the right index, but so far I could not find a way to get the right row, because the self.tableWidgetX.currentRow() returns the last row where a text-cell was entered. This means row is -1 when nobody clicked somewhere on the grid, and if you enter row 2, and then change the combobox in row 5, self.tableWidgetX.currentRow() will return 2!

As the row-number in Serges solution is passed plain this is also not a 100% solution as the row-sorting could be changed (user sorts data by clicking on headers, or rows are (re)moved/added by code). But if I prevent this at last the row-number should be correct.

For short, the way I've tested your solution:

    from PyQt5.QtWidgets import QComboBox

    @pyqtSlot()
    def on_pushButton_add_row_to_tableWidgetX_clicked(self):
            tWid=getattr(self, "tableWidgetX")
            tWid.setRowCount(tWid.rowCount()+1)
            combo = QComboBox()
            combo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
            combo.addItems(["A","B","C"])
            tWid.setCellWidget(tWid.rowCount()-1, 3, combo) # ComboBox goes to last row, column Nr 3
            tWid.setColumnWidth(3, combo.size().width())
combo.currentIndexChanged.connect(self.on_spk_ver_rep_QComboBox_currentIndexChanged)

    @pyqtSlot(int)
    def on_spk_ver_rep_QComboBox_currentIndexChanged(self, index):
        print(index,  self.tableWidgetX.currentRow())

george

Am 23.09.2018 um 19:11 schrieb Christos Sevastiadis:
Dear George,

I think that you should create a slot for the specific QComboBox object and not for the cell of the QTableWidget object. For example, for a QComboBox created in the Ui_MainWindow.setupUI(), the corresponding slot created in the MainWindow.setupUI() should have the following form, for integer or string type index.

    @pyqtSlot(int)
    def on_spk_ver_rep_QComboBox_currentIndexChanged(self, index):
        """
        Slot documentation goes here.

        @param index DESCRIPTION
        @type int
        """
        # TODO: not implemented yet
        raise NotImplementedError

    @pyqtSlot(str)
    def on_spk_ver_rep_QComboBox_currentIndexChanged(self, p0):
        """
        Slot documentation goes here.

        @param p0 DESCRIPTION
        @type str
        """
        # TODO: not implemented yet
        raise NotImplementedError

Christos



On Sun, 23 Sep 2018 at 15:40, GM <[email protected] <mailto:[email protected]>> wrote:

    Hi @all,

    I've created a dialog-window with an QTableWidget. Users can add a
    row
    by using a pushbutton. In a cell of the new row appears a
    QComboBox. How
    can changes of this QComboBox trigger a function?

    It's no problem for to text-only-cells (I can use:

         @pyqtSlot(int, int)
         def on_tableWidgetX_cellChanged(self, row, column):
             print("cell changed: ", row, column)

    which works as intended.)

    Functions like

         @pyqtSlot(QComboBox)
         def on_tableWidgetX_itemChanged(self, item):
             print("OK1")

         @pyqtSlot(QComboBox)
         def on_tableWidgetX_itemClicked(self, item):
             print("Ok2")

    never recieve a signal.

    I think the QComboBox can not send a aignal. Originally the "Generate
    Dialog Code..."-dialog suggests to pass a "QTableWidgetItem*" to the
    pyqtSlot, but this Item is created during runtime, so it can not be
    found in the Ui_Dialog...

    Any suggestions?


    george

    _______________________________________________
    Eric mailing list
    [email protected] <mailto:[email protected]>
    https://www.riverbankcomputing.com/mailman/listinfo/eric


--
Georg Mößlacher
+43-664-735 69 327

_______________________________________________
Eric mailing list
[email protected]
https://www.riverbankcomputing.com/mailman/listinfo/eric

Reply via email to