Why must I use Qt Designer 2.7 with Python 2.7? - python

Why can't I use other Qt series with different Python releases?

You can. If you have a specific version of Qt you would like to use, you can either download a matching PyQt version from Riverbank's download site or you can compile your own version of PyQt. I've had to build them from scratch a few times when the provided binaries didn't match the Qt/Python versions I wanted to use. It's a bit of a hassle to compile but it's definitely possible.
Also, note that the up-and-coming PySide library is an alternative Qt binding for Python that looks like it has a good chance of supplanting PyQt (due to looser licensing constraints).
Generally speaking, Qt Designer is an optional and independent component from PyQt. You can use it to create your .ui files but after that, it's up to the developer to determine how to use them... either generate Python code from them with pyuic4 or load them dynamically. As long as the format of the resulting .ui files are compatible with your version of PyQt, it shouldn't matter which Designer version you're using (though I would strongly recommend you use the version matching the Qt version PyQt is linked against).

Related

Why is the "build" tab inactive for me in qt?

I have installed qt (the open source version) and would like to code with python 3 in it. I write a code, however, I cannot compile it because the "build" tab and button are not active (they are grey). What can the problem be, and what should I do?
Short answer: Qt Creator is not designed for working with Python
Longer answer: The purpose of Qt Creator is really for using Qt in C++. Many of the features of the IDE revolve around that and will be unavailable if you aren't working with a Qt C++ project. This is why a "Build" menu exists: the commands there are for running the Qt and C++ compilers. Note that Python (a scripting language) does not require compilation, so it wouldn't make sense to attempt to compile your code anyway.
It might be that you're using Qt Creator because you're making use of one or more of the Qt modules that exist in Python (e.g. PyQt, PySide). These modules have been created as "bindings" to the Qt application framework allowing you to (for example) create Qt-style GUI applications in Python, but they have no requirement for you to use the Qt Creator IDE.
Alternatives: While Qt Creator is fine as a general code editor, in general I would recommend using another IDE for writing Python, such as Visual Studio Code (more flexible) or PyCharm (specifically for Python). If you want to stick with Qt Creator you can configure it to allow you to run your Python like this.
Finally, it's worth pointing out that it's possible to use the Qt Creator UI designer and then export the created files into a Python Qt application. See this question and its responses for more info.

Use Anaconda's Python in my Qt C++ application

I intent to use Anaconda's Python in my Qt C++ application to call some scikit-learn algorithms from within my C++ code. For some reason I cannot figure out how to do the integration. I wonder if anybody knows a step by step procedure to do so.
If your C++ code works with Qt <= 5.9.7. (or more precisely Anaconda's current Qt version) you can include Python (in this case 3.6) by adding
INCLUDEPATH += /home/[username]/anaconda3/include/python3.6m
LIBS += -L/home/[username]/anaconda3/lib/ -lpython3.6m
to your .pro file.
If you need a Qt version which is higher than the one provided by Anaconda, have a look at my question here. Now you should be able to include the Python.h header in your application.
Remark: Keep in mind that Python provides its own signals and slots mechanism which can apparently clash with Qt's. That's why I added
CONFIG += no_keywords
to my pro file, and replaced all signals and slots occurrences like described here.
I am not sure this would work for you, but I'd look at this article. It provides at least a way to start a python interpreter from within the Qt application.
I think this might work, depending on the complexity of the thing.
You can find more on the PythonQt.
I don't know how well it will work with external packages though.
Otherwise, you could use PySide2, which allows you to create GUIs using Qt5 framework in python.
I hope it helps.

QT python GUIs : how to view code in qt designer

I want to learn to use qt designer and i want to know what to install, because I've had some issues with python versions and distributions. This is my first time doing this I know basically nothing about python or QT. I appreciate your help
Qt Designer is just a quick way to visually define the GUI. You can then load the .ui files created there in you python application or convert them to python code: Convert pyQt UI to python. But I would rather recommend you to write the code from scratch by yourself. This way you can better understand how the things are actually work.
Qt is a C++ framework, if you want to use it with python you have to pick a python binding first. You basically have two choices here: PyQt and PySide. PyQt is proprietary software developed by Riverbank Computing Limited. PySide is open source software and nowadays the official Qt binding for python.
Similar to python with its major versions 2 and 3, Qt has two major versions Qt4 and Qt5 that are widely used. PyQt4 and PySide are Qt4 bindings, PyQt5 and PySide2 are Qt5 bindings.
So if you have no specific requirements regarding the version you should use, just install the latest version of Python, install PySide2 using pip and enjoy studying GUI programming with Python and Qt!

Easy way to create a python interpreter widget in a Qt C++ app?

My app is written in C++. I use Qt for the GUI. I have built python bindings for the the core of my app.
I would like to create an interpreter widget that would let the user access an embedded python interpreter where they can use my own python bindings to script operations available in the app.
The widgets I've been able to find online all assume one is using PyQt, but I want to do this in straight C++/Qt. Has anybody developed a Qt widget in C++ that I could reuse?
AFAIK Qt does not provide a way to do that right now through a standard Qt component, there is a library called PythonQt that tries to accomplish what you need, but it only supports Qt 4. If that is acceptable then go for it, otherwise, you should download the python source code, compile it and then start here to see how to embed the interpreter in your application.
If you also want to expose parts of your application to the interpreter, you will have to use the Python C api to create a wrapper, you might be able to use SWIG to minimize the amount of work you have to do

How does Qt work (exactly)?

When you write an application using Qt, can it just be run right away in different operating systems? And (correct me if I'm wrong) you don't need to have Qt already installed in all of the different platforms where you want to execute your application?
How exactly does this work? Does Qt compile to the desired platform, or does it bundle some "dlls" (libs), or how does it do it? Is it different from programming a Java application, that runs cross-platform.
If you use Python to write a Qt application with Python bindings, does your end user need to have Python installed?
Qt (ideally) provides source compatibility, not binary compatibility. You still have to compile the application separately for each platform, and use the appropriate dynamic Qt libraries (which also need to be compiled separately, and have some platform-specific code).
For your final question, the user would need Python, the Qt libraries, and the binding library (e.g. pyqt), but there are various ways to bundle these.
PyQT [and its open source cousin PySide] are a great cross-platform QT binding for python, but it is not a magic solution for shipping your application for all platforms without doing any packaging/installer maintenance. I think maybe you might be expecting some magic.
QT is a cross-platform library written in C++. That means, you can write your C++ or Python (or other language with bindings) code once, and create a "window" (a form, a dialog box, something on the screen) and populate it with controls (buttons, and all that) and not have to deal with the platform differences in how buttons are made in Windows, Linux, and on Mac OS X.
Because it is a library, it can be packaged in multiple ways. It can be "statically linked" (built into your executable/binary/app) or "dynamically linked" (known as a DLL in windows, a shared library or on unix/linux or as a framework, in mac os x). It is not always "installed" on a computer, unless it is a shared library.
Even when it is "installed" onto a computer, multiple versions might exist on that computer, and so it is not proper to think of it as being an extension to your computer, but rather an extension to an application (a program) on your computer.
If you use Python bindings for QT, then your installation package for your application needs to include the QT binding's binary files (python extensions), the basic Python runtime environment including the Python executable and basic libraries, and your program's source code. It is possible to package most of this up into a single "bundle". On Mac OS X, for instance, all this can easily be put into a an ".app" bundle, and on Windows, and Linux, I believe there are packaging and installation tools that can help you do this easily.
Even though you will only need to write the user interface code for your application once, you will not magically get the ability to ship an application on all three primary platforms at once, without doing at least the building of the installer or packaging, separately for each platform. Users expect to download a setup/install package for Windows or Mac OS X, and perhaps for Unix/Linux it depends further on which distribution you install.
Update thanks to AdamW for this nokia link providing deployment information
The problem is your definition of "installed". For Qt to work, the executable just has to have access to the proper libraries.
Of course that for each platform a different executable and libraries have to be produced (see Qt docs).
About Python, if you are to run a Python executable you have to have it installed (in a more traditional kind of way). Unless you are running with py2exe in Windows, for instance.

Categories

Resources