Ejemplo n.º 1
0
class VisualController(Controller):
    def __init__(self):
        super().__init__()
        self.results = QStringListModel(["Worker Results:"])
        self.listview = QListView()
        self.listview.setModel(self.results)

    def start(self):
        super().start()
        self.listview.show()

    @Slot(int)
    def on_worker_result(self, result: int):
        super().on_worker_result(result)
        row_count = self.results.rowCount()
        assert self.results.insertRows(row_count, 1)
        new_row_idx = self.results.index(row_count, 0)
        self.results.setData(new_row_idx, str(result))
        self._resize_to_fit_contents()

    def _resize_to_fit_contents(self):
        QApplication.processEvents()
        view_geo = self.listview.geometry()
        view_geo.setHeight(
            max(view_geo.height(),
                self.listview.contentsSize().height()))
        self.listview.setGeometry(view_geo)
Ejemplo n.º 2
0
def using_model():
    app = QApplication()
    numbers = ['One', 'Two', 'Three', 'Four', 'Five']

    model = QStringListModel()
    model.setStringList(numbers)

    list = QListView()
    list.setModel(model)

    firstTableView = QTableView()
    secondTableView = QTableView()

    firstTableView.setModel(model)
    secondTableView.setModel(model)
    secondTableView.setSelectionModel(firstTableView.selectionModel())

    list.show()
    firstTableView.show()
    secondTableView.show()
    app.exec_()
Ejemplo n.º 3
0
from PySide2.QtCore import QStringListModel
from PySide2.QtWidgets import QApplication, QListView, QComboBox

if __name__ == '__main__':
    """
    Using a model for two different views
    Now the changes in QListView will be shown in QComboBox
    """

    app = QApplication(sys.argv)

    # Let's make the QListWidget show this data
    data = ["ONE", "TWO", "THREE", "FOUR", "FIVE"]

    list_widget = QListView()
    list_widget.show()

    model = QStringListModel(data)

    # Setting the model to our QListView
    list_widget.setModel(model)

    # Another view
    comboBox = QComboBox()
    comboBox.show()

    # The new view uses the same model
    comboBox.setModel(model)

    sys.exit(app.exec_())
# <div>Icons made by <a href="https://www.flaticon.com/authors/egor-rumyantsev" title="Egor Rumyantsev">Egor Rumyantsev</a> from <a href="https://www.flaticon.com/" 			    title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" 			    title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>


def supported_image_extensions():
    ''' Get the image file extensions that can be read. '''
    formats = QImageReader().supportedImageFormats()
    # Convert the QByteArrays to strings
    return [str(fmt) for fmt in formats]


if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)

    lst = QListView()
    lst.setMinimumSize(600, 400)
    model = QStandardItemModel(lst)

    item = QStandardItem()
    item.setText('Item text')
    item.setIcon(QIcon('icons/table-grid.svg'))
    item.setEditable(False)

    model.appendRow(item)

    lst.setModel(model)

    lst.show()

    sys.exit(app.exec_())
Ejemplo n.º 5
0
    def setData(self, index, value='', role=Qt.EditRole):
        row = index.row()

        if role == Qt.EditRole:
            self.status[row] = value
            self.dataChanged.emit(index, index)  # inform the other view to request new data
            return True
        else:
            return False


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)

    myModel_on_mywindow = MyModel([1, 2, 3])
    mywindow = Window(myModel_on_mywindow)
    mywindow.setWindowTitle('myModel_on_mywindow')
    mywindow.show()
    myModel_on_mywindow.status[0] = 2

    myModel_on_qlistview = MyModel([1, 2, 3])
    qlistview = QListView()
    qlistview.show()
    qlistview.setModel(myModel_on_qlistview)
    qlistview.setWindowTitle('myModel_on_qlistview')

    myModel_on_qlistview.status[0] = 2

    sys.exit(app.exec_())