While this question has already been answered at Embeding PySide/PyQt widget into Qt/C++ application . I could not reproduce the code because I did not have OPs functions and more importantly the post is 8+ years old and QT has developed a lot since then, especially when it comes to Python.
I need a method to have my PySide widget called by C++ QT main window/application and essentially work as a QColor, I need to call it and it will return a value just like how QColor works.
Simplified explanation:
I need to call my PySide widget in C++ QT like this
a = CustomPySideWidget()
I need to be able to recieve data to the variable a, this data can be returned as a simple string so the data type will be C++ compatible.
Is there any methods to do this via PySide or PyQT?
Thank you for any help.
Related
I am currently working on a GUI application using PyQt5 and QtDesigner. As I have to make it multi-platform (at least Ubuntu and W10) I will use the "Fusion" style to make it look similar on both platforms.
I was wondering if one could simply set the QApplication style directly in QtDesigner ? I know that a simple <<.setStyle("Fusion")>> will do the trick in the code, but does it exist within QtDesigner so the lines can be automatically generated ?
I'm trying to learn QtDesigner and how much it can be pushed before going into the code.
No, it is not possible to set the style through Qt Designer.
What Qt Designer does allow is to display the GUI with different styles if you select Form-> Preview -> ...
I am working on a module for 3D slicer. A chunk of the template code is pasted below. It is using qt for GUI. I need to add my own GUI here, But I am not able to find how to add toolbar here. I am not able to find any documentation regarding this. Whenever I google I get PyQt4, is that different from this ? So, my question is please explain the diference between qt and PyQt4 and how can I add toolbar here ?
def __init__(self, widgetClass=None):
self.parent = qt.QFrame()
self.parent.setLayout( qt.QVBoxLayout() )
# TODO: should have way to pop up python interactor
self.buttons = qt.QFrame()
self.buttons.setLayout( qt.QHBoxLayout() )
self.parent.layout().addWidget(self.buttons)
self.addDataButton = qt.QPushButton("Add Data")
self.buttons.layout().addWidget(self.addDataButton)
self.addDataButton.connect("clicked()",slicer.app.ioManager().openAddDataDialog)
self.loadSceneButton = qt.QPushButton("Load Scene")
self.buttons.layout().addWidget(self.loadSceneButton)
self.loadSceneButton.connect("clicked()",slicer.app.ioManager().openLoadSceneDialog)
import statement
import vtk, qt, ctk, slicer
I think the form/GUI is created by tool. You can have a look at this
You can add your PyQt4 code in this, that should work fine.
If the import statement is qt, 2 solution : it use an alias (it would be weird) or it use a pyqt wrapper which allow to use PySide2, PyQt5, PySide and PyQt4 the same base code.
Maybe this one : https://github.com/mottosso/Qt.py
maybe another ... If you have a requirement.txt you should be able to know
please explain the diference between qt and PyQt4
Qt is cross-platform application framework, using C++ extensions.
In order to use it in python you need a wrapper and this is what PyQt, PySide and the rest are.
Check your application documentation and probably you will find if it uses PyQt4,5, PySide or something else.
I have a very complex custom widget derived from QWidget in PySide.
At first its paintEvent was taking more than 1 second to complete. Then I've implemented a lot of caching with QPixmap to each layer of the "image" that I'm drawing. Now my paintEvent finishes in about 90ms - which is really fine, but not enough.
I'm wondering if I can implement this custom widget in plain C or C++, and then use it as an abstract widget in PySide (like PySide does with all other available widgets).
I found here that in PyQt I could use sip for this. But I can't find a match for this in PySide.
Does any one know how to do that?
I am trying to write a custom widget for the Qt Designer using only Python. I was following a couple of tutorials I found online but none of them were working or anything close to what I would call to be a minimum working example.
So my questions are:
What steps are involved to make a a custom widget appear in the Widget Box of Qt Designer?
If you can spare the time: Please provide a minimum working example (like a widget with a label in it saying "A truly minimal working Qt custom widget example").
Or is it maybe not possible at all to include a custom widget using only python?
There are very few examples available on how to make a custom widget in pyqt. I wrote this article with a working example: Making a Custom Widget in PyQt
Here is the answer to your question #3: How do I use promote to in Qt Designer in pyqt4?
I am using PySide and it works the same way. This method works directly with your Python custom widget code. You do not need to write any separate plugin code.
After you have promoted your custom widget, you can right click on it and add your signals with "Change signals/slots..."
I would recommend putting all you widgets in a YourCostumWidgetsPack.UI file, and then when you load this file in Qt Designer, in addition to the UI you are working. It will load all your custom widget information.
I found this article to be your answer: https://doc.qt.io/archives/qq/qq26-pyqtdesigner.html
But, I haven't been able to install it in Qt Designer though :D
Howdo,
I've just started getting into Python and QT. I have a very simplistic question. I wanted to create a Qt window to display the output and accept input from a program that I am attempting.
My question is, in Qt Designer I have made said window, but I'm not sure if I have to set the signals and slots in designer or in python. For the output I had used a QtextBroswer widget and a QPlainTextEdit for the input. Are those the correct choices for my uses.
Also do I need to muck about with setting slots and signals in Designer, or no?
Any and all help would be greatly appreciated.
Set the signals and slots in Python. When you export the ui to Python using pyuic4 or pyside-uic, the signals and slots are set using python anyways.