T
T
TemaKam2021-01-05 12:37:28
Python
TemaKam, 2021-01-05 12:37:28

Why are functions not attached to buttons on the widget being created from my class?

when a button is pressed, I call a class function (from another module), which returns a form (with buttons, etc.)
all actions that are written in __init__ are performed, and when I tried to bind a function to a button in this class, this function is created on the form being created doesn't work anymore
why?

in short, the code is something like this:
module 1.py

from 2.py import Task
...
self.tasks.addTab(Task(параметры __init__).new_task(), self.task_name.toPlainText())

module 2.py:
class Task:
    def __init__(self, параметры):
        super().__init__()
        self.tab_2 = QtWidgets.QTabWidget()
        self.tab_2.setObjectName("tab_2")
        # кнопка для примера
        self.start_task = QtWidgets.QPushButton(self.tab_2)
        self.start_task.setGeometry(QtCore.QRect(300, 510, 171, 23))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.start_task.setFont(font)
        self.start_task.setObjectName("start_task")

        self.start_task.clicked.connect(self.test)

    def new_task(self):
        return self.tab_2

    def test(self):
        print('111')

so it turns out that the form with the button is created (well, other objects are still there), but the action on pressing the button does not occur

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bbkmzzzz, 2021-01-05
@TemaKam

class Task:
    def __init__(self, параметры):
        super().__init__()

What is the class inherited from? How does the application start?
The clicked signal is emitted when the button is clicked. Signals can only be emitted and received by QObject descendants, and only in the main event loop. Task is not.
Either we supplement the code, or we go to read about Qt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question