Qt and Python, where to configure signals and slots - python

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.

Related

Is it possible to set QApplication style in QtDesigner?

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 -> ...

Qt Designer and Frameless Window

I am currently creating a GUI for an application and I want to make it frameless and add the minimize and close buttons myself. What I want to achieve can be seen in this answer:
The window structure I want to achieve
Since the GUI structure that I have in mind is really complex I really need that I have to use Qt Designer. Is there a way to achieve what is done in the answer above in the Qt Designer?
One way to achieve this is to create your application window as usual in Qt Designer, load the .ui file in the python via uic.loadUi and add it to the layout of box.contentWidget() instead of the edit in the linked example.

Creating a multi-screen application using Qt Designer

I'm using Qt Designer to create UI designs which I'm then converting into python code. Since I'm quite new to Qt I'd like to ask: is there a way I could implement a multi-screen application? I.e. having a next button clicked and getting a new set of options/widgets etc within the same window.
To be honest, I was developing using Kivy, and as slick as that is (especially with multiple screens) it depends on PyGame, which proves to be an enormous portability headache, so I had to switch to something else, and PyQt was the next feasible option (or so it seems).
It's called a QWizard. It is not called a multi screen application, but if you search for wizard instead, you find lots of information.
Links
Example with C++ code
[PyQt QWizard documentation] http://pyqt.sourceforge.net/Docs/PyQt4/qwizard.html

Custom Qt Widgets with python for Qt Designer

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

getting keyboard events with pyqt

i converted recently from wxpython to pyqt and im still facing alot of problems since im still noob in pyqt
so is it possible to detected if user pressed (CTRL+key ) in pyqt ? and how ?
i've been trying to find an answer for this for 3 days . if you know website or a good place to learn pyqt, it will be highly appreciated
thanx in advance
Add a QShortcut and listen to its activated() signal, then perform the action in the slot.
Or you could reimplement QWidget and define keyPressEvent to what you like. Check for the event parameter's modifiers() and key() to see if they match with what you want. This listens for shortcut keys when the QWidget has focus.
As for websites to learn, this is the official documentation - it takes some getting used to, but is quite helpful once you get the lay of the land (so to speak). This tutorial is what I walked through to get the initial idea, before discovering the documentation.
Good luck!
P.S. You might also look at QAction, if you are trying to map your Ctrl+X to an action that may also be performed by a menu or toolbar button... It incorporates a shortcut along with icons and/or text in a very convenient package. Just FYI.

Categories