pyside2

How to connect Python and QML with PySide2?

末鹿安然 提交于 2019-12-03 07:52:47
问题 I want to write a simple desktop application on Ubuntu and I thought that an easy way was to use Qt with QML as GUI and Python as the language for the logic, since I am somewhat familiar with Python. Now I am trying for hours to somehow connect the GUI and the logic, but it is not working. I managed the connection QML --> Python but not the other way around. I have Python classes which represent my data model and I added JSON encode and decode functions. So for now there is no SQL database

How to connect Python and QML with PySide2?

元气小坏坏 提交于 2019-12-03 00:35:11
I want to write a simple desktop application on Ubuntu and I thought that an easy way was to use Qt with QML as GUI and Python as the language for the logic, since I am somewhat familiar with Python. Now I am trying for hours to somehow connect the GUI and the logic, but it is not working. I managed the connection QML --> Python but not the other way around. I have Python classes which represent my data model and I added JSON encode and decode functions. So for now there is no SQL database involved. But maybe a direct connection between QML view and some database would make things easier? So

PySide2 Signal with named parameter

ぐ巨炮叔叔 提交于 2019-12-02 07:24:16
问题 I am trying to replicate below example using PySide2. https://evileg.com/en/post/242/ But as PySide2 doesn't support emitting a Signal with named parameter to QML, i have no clue about how to do this using PySide2 ? Here is my code main.py from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine from PySide2.QtCore import QObject, Signal, Slot, Property class Calculator(QObject): def __init__(self): QObject.__init__(self) sumResult = Signal(int) subResult =

Connect QML signal to PySide2 slot

亡梦爱人 提交于 2019-12-02 07:19:23
I have some expirience using Qt/C++ and now I want to switch to PySide2 + QML. I want to connect ui signals, such as clicking a button, to python slot I have seen many examples, but they all differ, i guess PyQt/PySide is changing quickly now Can you provide me modern and clean way of connecting a QML signal to PySide Slot? For example clicking a Button to printing some text in python console. Here's my simple code example main.py from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine def test_slot(string): # pseudo slot print(string) if __name__ == "__main__

PySide2 Signal with named parameter

拈花ヽ惹草 提交于 2019-12-02 05:13:51
I am trying to replicate below example using PySide2. https://evileg.com/en/post/242/ But as PySide2 doesn't support emitting a Signal with named parameter to QML, i have no clue about how to do this using PySide2 ? Here is my code main.py from PySide2.QtGui import QGuiApplication from PySide2.QtQml import QQmlApplicationEngine from PySide2.QtCore import QObject, Signal, Slot, Property class Calculator(QObject): def __init__(self): QObject.__init__(self) sumResult = Signal(int) subResult = Signal(int) @Slot(int, int) def sum(self, arg1, arg2): self.sumResult.emit(arg1 + arg2) @Slot(int, int)

Using a custom PySide2 widget in Qt Designer

£可爱£侵袭症+ 提交于 2019-12-02 05:10:40
I'm searching for a way to use custom widgets in Qt Designer written with Qt for Python (PySide2) effectively. I found out, that it is possible to design the GUI with the base widget, then just swap out the class to my custom widget in the UI File and informing the QUiLoader about the subclass loader.registerCustomWidget(MyMainWindow) , but then opening it again in Qt Designer doesn't work that well. I read in this similar question for PyQt that you have to write a Plugin for the custom widget. Does this possibility also exist for PySide2? Some example code: custom_widget.py: import sys from

PySide2 paint on widget created by designer

放肆的年华 提交于 2019-12-02 04:56:41
This issue is with VS Code on Win10 and Python 3.6.6. I'm new both to Python and PySide2. I've read a lot of topics on this here at StackOverflow and possibly this is a duplicate of another topic, but I'm not able to get my widget painted. I understand that the paintEvent() of the widget object have to be overridden somehow. Most of the examples out there does some painting on the main window but I'm not able to transfer this on widgets from an ui.file. I've created two classes in my .py-file, MainForm and Drawer. The MainForm contains implementation of UI and I'm trying to get a widget (named

PySide2 not updating QLabel text when asked

孤者浪人 提交于 2019-12-02 01:39:48
问题 I am upgrading from Python 2.7 to Python 3.6 and from PySide to PySide2. I started by trying to get the "Hello World" from the "Getting Started" site (https://doc-snapshots.qt.io/qtforpython/gettingstarted.html) working. It displays the widget, its label and the push button, but the push button does not change the text of the label. I added a print() to verify that the button is indeed calling the method associated with the click signal, and even added an update() to try to "encourage" it a

background color of cells in QTableview, PySide2

早过忘川 提交于 2019-12-02 01:20:59
Is it possible to conditionally change the background color of items in a QTableView, using PySide2? I've read a lot on the model view framework . I cannot figure out if it is necessary to use a Delegate or not. Recently I was able to get a column of checkboxes without a Delegate. I believe that the virtual methods setItemData(index, roles) and itemData(index) could be what I need. However, there is no QMap in PySide2. My model must need somewhere to store the extra information to be used by QtCore.Qt.BackgroundRole (that enum, btw, says "the background brush used for items rendered with the

Text styling in QTableView with PySide2

拈花ヽ惹草 提交于 2019-12-01 14:21:18
I have a QTableView populated with a proper model. I would like to change the style of the text based on the context of it: The text, if there is something between parenthesis, just this part of text should change to green color -parenthesis included- (and bold, just if it is not harder). If you can provide a snippet or super simple example, I appreciate it. You have to use a delegate that uses QTextDocument : import random from PySide2 import QtCore, QtGui, QtWidgets words = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris euismod cursus mi sit amet pellentesque. Proin sed