SHARE
TWEET

Untitled

a guest Apr 25th, 2019 183 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. import sys
  3. from PySide2 import QtCore
  4. from PySide2.QtGui import QStandardItemModel, QStandardItem
  5. from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QListView, QLineEdit
  6. from PySide2.QtUiTools import QUiLoader
  7.  
  8. def form():
  9.     def item_changed(item):
  10.         print("New value {} at index {}".format(item.text(), item.row()))
  11.  
  12.     def item_select(index):
  13.         item = model.itemFromIndex(index)
  14.         print("Selected {} at index {}".format(item.text(), item.row()))
  15.         form.edit.setText = "Selected {} at index {}".format(item.text(), item.row())
  16.  
  17.     form = QUiLoader().load("form.ui")
  18.     form.resize(100, 200)
  19.     form.setWindowModality(QtCore.Qt.ApplicationModal)
  20.  
  21.     form.label.setText("Выбирай что хочешь")
  22.  
  23.     model = QStandardItemModel()
  24.  
  25.     for name in ["Pascal", "PHP", "Python"]:
  26.         item = QStandardItem(name)
  27.         model.appendRow(item)
  28.  
  29.     form.list.setModel(model)
  30.    
  31.     model.itemChanged.connect(item_changed)
  32.     form.list.clicked.connect(item_select)
  33.  
  34.     return form
  35.  
  36. app = QApplication(sys.argv)
  37.  
  38. window = QWidget()
  39. window.resize(400, 300)
  40.  
  41. form = form()
  42.  
  43. button = QPushButton("Open Form", window)
  44. button.setToolTip("Click here and you'll see")
  45. button.setGeometry(150, 130, 100, 30)
  46. button.clicked.connect(lambda: form.show())
  47.  
  48. window.show()
  49.  
  50. sys.exit(app.exec_())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top