파이썬의 pyqt5 관련된 글
생각날때 마다 정리하기
self.modeLineEdit.setText(text)
self.modeLineEdit.text()
self.tempTableWidget.setColumnWidth(0, 80)
self.tempTableWidget.setColumnWidth(1, 150)
self.tempTableWidget.setColumnWidth(2, 100)
self.tempTableWidget.setColumnWidth(3, 50)
Qt Desinger
로 만들면 코드로 변경이 가능하다.
tableIndex = self.keywordListTable.rowCount()
self.keywordListTable.setRowCount(tableIndex + 1)
self.keywordListTable.setItem(tableIndex, 0, QTableWidgetItem(keyword["page"]))
self.keywordListTable.setItem(tableIndex, 1, QTableWidgetItem(str(len(keyword["keyword"]))))
self.keywordListTable.setItem(tableIndex, 2, QTableWidgetItem(keyword["keyword"]))
새로운 row를 추가 후 값을 정의한다.
QApplication.processEvents()
# form_class는 ui resource 변수
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = WindowClass()
myWindow.show()
app.exec_()
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
form = resource_path("**.ui") # ui이름
form_class = uic.loadUiType(form)[0]
self.pushButton.clicked.connect(lambda: testAdapter(self, searchService))
버튼을 눌렀을 때 testAdapter
메서드가 호출된다.
def testAdapter(self, searchService):
""" setCommonLineEdit 내용
def setCommonLineEdit(self, text):
self.commonLineEdit.setText(text)
"""
searchService.modeLineEdit.connect(self.setCommonLineEdit)
searchService.start()
class SearchService(QtCore.QThread):
cnt = 0
startStatus = False
# 시그널 등록
commonLineEdit = QtCore.pyqtSignal(object)
def __init__(self, parent):
# parent를 써서 ui에서 값을 가져옴
QThread.__init__(self, parent)
self.parent = parent
def run(self):
self.startStatus = True
self.extraction()
def keywordExtraction(self):
# ui에서 값가져오기
commonText = self.parent.commonLineEdit.text()
# ui에 값세팅
# 쓰레드가 동기화된다.
self.commonLineEdit.emit("일반")