Created
August 31, 2020 19:21
-
-
Save aijaz/1de0202762a3d5b528981e4106f22125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PyQt5.QtWidgets import QApplication, QListWidget, QMainWindow | |
class MainWindow(QMainWindow): | |
def __init__(self): | |
super().__init__() | |
self.setWindowTitle("My App") | |
self.widget = QListWidget() | |
self.widget.addItems(["One", "Two", "Three"]) | |
for i in range(1,50): | |
self.widget.addItem("New Item " + str(i)) | |
# In QListWidget there are two separate signals for the item, and the str | |
self.widget.currentItemChanged.connect(self.index_changed) | |
# self.widget.currentTextChanged.connect(self.text_changed) | |
self.setCentralWidget(self.widget) | |
def index_changed(self, i): # Not an index, i is a QListItem | |
print(self.widget.currentRow()) | |
def text_changed(self, s): # s is a str | |
print(s) | |
app = QApplication(sys.argv) | |
window = MainWindow() | |
window.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment