오류가 있습니다. 어떻게 제공합니까? 제거 버튼이있는 위젯을 제거하고 싶습니다. 괜찮습니까 self.removeButton.clicked.connect(self.removing.remove_widget)
? 푸시 버튼으로 다른 클래스에 연결하려고했습니다.다른 클래스 (PyQt)에서 버튼을 클릭하여 위젯을 제거하는 방법
from PyQt4 import QtGui, QtCore
import sys
class Main(QtGui.QMainWindow):
def __init__(self, parent = None):
super(Main, self).__init__(parent)
# main button
self.addButton = QtGui.QPushButton('button to add other widgets')
self.addButton.clicked.connect(self.addWidget)
self.removing=Test()
self.removeButton=QtGui.QPushButton("remove widget")
self.removeButton.clicked.connect(self.removing.remove_widget)
# scroll area widget contents - layout
self.scrollLayout = QtGui.QFormLayout()
# scroll area widget contents
self.scrollWidget = QtGui.QWidget()
self.scrollWidget.setLayout(self.scrollLayout)
# scroll area
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setWidget(self.scrollWidget)
# main layout
self.mainLayout = QtGui.QVBoxLayout()
# add all main to the main vLayout
self.mainLayout.addWidget(self.addButton)
self.mainLayout.addWidget(self.removeButton)
self.mainLayout.addWidget(self.scrollArea)
# central widget
self.centralWidget = QtGui.QWidget()
self.centralWidget.setLayout(self.mainLayout)
# set central widget
self.setCentralWidget(self.centralWidget)
def addWidget(self):
self.scrollLayout.addRow(Test())
class Test(QtGui.QWidget):
def __init__(self, parent=None):
super(Test, self).__init__(parent)
self.lineEdit = QtGui.QLineEdit('I am in Test widget')
layout = QtGui.QHBoxLayout()
layout.addWidget(self.lineEdit)
self.setLayout(layout)
def remove_widget(self):
self.lineEdit.deleteLater()
app = QtGui.QApplication(sys.argv)
myWidget = Main()
myWidget.show()
app.exec_()
어떤 오류가 발생합니까? –