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

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.

Related

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!

Is there a way to create a GUI in python, like in VisualStudio or AndroidStudio?

I wanted to know if there is a program like VisualStudio or AndroidStudio for python.
I mean, a program that can create a visual GUI and I just need to program the buttons I had planed in the GUI I made.
PySide or PyQT require QT which allows you to use Qt Creator.
http://en.wikipedia.org/wiki/Qt_Creator
It's a bit of a workaround but the libraries come with a script (e.g. pyside-uic for pyside) which can convert qt creator files into python classes. You'll also need to setup another class which reads and creates the gui's, but this is all documented for pyside online here:
http://qt-project.org/wiki/QtCreator_and_PySide
A quick web search brings up a few possibilities:
http://wiki.wxpython.org/wxPythonPit%20Apps#Programming:_GUI_tools
http://wxglade.sourceforge.net/
https://wiki.python.org/moin/GuiProgramming
https://wiki.python.org/moin/GUI%20Programming%20in%20Python
Like #kartikg3 asked, what platform are you working/deploying on?

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

Why must I use Qt Designer 2.7 with Python 2.7?

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

Creating GUI with Python in Linux

Quick question.
I'm using Linux and I want to try making a GUI with Python. I've heard about something like Qt, GTK+ and PyGTK but I don't know what they are exactly and what the difference between them is.
Is there any difference on how they work with different DEs like GNOME, KDE, XFCE etc.? Is there any IDE that allows you to create GUI like Microsoft Visual Studio does (for C#, C, Visual Basic etc.)?
Or should I maybe use another language other than Python to make GUI applications?
Your first step should be http://wiki.python.org/moin/GuiProgramming
Some tool-kits integrate better in one environment over the other. For example PyQt, PyKDE (and the brand new PySide) will play nicer in a KDE environment, while the GTK versions (including the WX-widgets) will blend better into a GNOME/XFCE desktops.
You should look at the environment you want to target. You can go for basic portable GUI kit, or you can to a deeper integration with tour DE, like use of integrated password manager, and configuration file parsers, that are integrated in a specific DE like KDE or GNOME.
You should also consider the dependency that your selection dictates, and what is come by default with a basic DE. For example, PyKDE in the KDE 3.X branch had a non trivial set of dependencies, while at the 4.X branch the plasma binding made the Python GUI programming dependency less of an issue.
There are several IDE tools, in different levels of completeness and maturity. The best thing is to try one ore more, and see what best fit your needs.
I would avoid using another language to make a GUI for Python.
I've had every good luck with wxwidgets, which is the python binding for WX, a cross-platform development system. It's pretty easy to learn and quite powerful. The problem with wxwidgets is that it is not installed by default, so your users will need to install it on every platform that they wish to run your application. Find more information about it at http://wxwidgets.org/.
If you want people to be able to use your program without installing anything else, use Tkinter, the GUI system that comes with Python.
I would avoid the Python bindings for GTK or KDE unless you already know those systems. They also need to be downloaded, and they do not seem to have as much adoption as wxwidgets.
Each desktop environment uses a specific toolkit to build it's components. For example, KDE uses Qt and GNOME uses Gtk.
Your use of a toolkit will be dependent upon what type of desktop environment you're targeting at, and if you want to target a wide range of desktops then use a toolkit which will work on many desktop environments, like Wx widgets which will work on Linux, Mac OS and Windows. For building simple GUI applications, Tkinter will do.
Use the glade UI designer and pyGtk bindings... that was my first ever experience with python and there are lots of blog posts and tutorials to help you get started
Use PyGTK. As important as the toolkit is its underpinnings, with PyGTK you use GLib as well, with its filesystem abstractions (python module gio) that are very important for the Linux desktop, its high-level cross-desktop functions such as glib.get_user_data_dir() and its other application framework tools, and GObject and its property and signals model.

Categories

Resources