I've been some reading/watching some tutorials here and there about qt quick and qml from last few days. But the user interface of qt creator, the boilerplate that it produces on a new qt quick project in each of the tutorial had been different. there's so much confusion.
I want to make a simple Hello World Qt Quick project, I followed this book from packt. (It has changed from the last time I saw it, but still doesn't work)
I added some a UI file, which added *.ui.qml and *form.qml files. Now if I edit .ui.qml in design, No change is reflected on any other file, but if I open some other file in design, it prompts me to use the .ui.qml file instead. The examples give an error "No Cmake config found". I'm using Qt6.2 on Arch/wayland, downloaded via installer.
How is it supposed to work? I have read this answer, and few others but I'm still confused.
Could you link to a proper tutorial, or a simple example?
The best way to think about it is that *.ui.qml should be used for UI elements and their settings. They should be about the structure, layout and styling of your UI. Doing that also happens to make the files presentable and editable in Creator's Design Mode since it simplifies the structure of the QML to the point where it can reliable present it and modify it.
*.qml files on the other shouldn't have UI elements and should instead primarily contain functions, properties and signal handers.
This pattern is sometimes referred to as "code behind". It sort of follows the same philosophy with HTML and CSS. Modern HTML documents primarily represent the structure of a page while CSS is placed in separate files to govern how they should be styled.
In this case *.ui.qml files contain the structure and styling while *.qml files containing the behavior. Creator will create a pair of them while adding a QML UI resource to your project where the .qml file inherits from the .ui.qml file.
Other than this inheritance and to encourage the code behind pattern, there's no real difference between a .qml and .ui.qml file. Creator will also try to steer you to the .ui.qml version of the pair when you go into designer to help encourage this pattern.
I will note that Qt violates this pattern a bunch all over their documentation and examples....
Related
I recently started playing with Qt and PyQt, then I learned about Qt Designer and the .ui files they generate in xml format.
I was wondering if there is a resource website for downloading the template .ui files? That would make life much easier to start with.
As i know, it's not such practice in Qt to make template .ui files and then reuse them. If you want to reuse some ready UI components you can make Qt Designer Plugin and then use it. See documentation: Adding Qt Designer Plugins
There's no point to template .ui files because the only truly reusable element in them is styling. Layouts etc. are very application-specific. Certainly Qt style .css/.qss templates make sense. If any exist, you will find them with Google.
When I looked at some of the GUI examples, I noticed some of the projects contains Forms folder and XXXX.ui files allowing user to modify the layout on the Design screen. But some of them don't have Forms folder and ui files but still have GUI to display.
So the GUI display on above latter cases are hand-coded and the other is using Designer. Is there a way to convert these two kind of projects from one to another?
Those .ui files are used by the User Interface Compiler[1] to generate some file named ui_formname.h that contains a class, Formname, inside the Ui namespace. So ultimately, everything resumes to C++ code
[1] http://qt-project.org/doc/qt-4.8/uic.html
I have a form generated dynamically from a database table model:
I there a way to save that form to a *.ui file? I want to allow user to edit that form in Qt Designer.
Presumably there must be some limitations on what your users can add and edit?
If so, then maybe you could take a more structured approach and use QWizard to provide a simple interface for designing and editing forms. The wizard would generate ui files which would then be loaded in your application using the uic module (if you're using PyQt4, that is - because it does not include the QUiLoader class).
Of course, for this to work, you would need to adapt your current procedure for dynamically generating forms so that it also works with ui files.
EDIT
It looks like QAbstractFormBuilder provides an API for both loading and saving widgets as ui files. It is part of the QtDesigner module, which is now included in PyQt4.
Having said that, my brief experimentation with the load() and save() methods did not produce very useful results - but hopefully others will have more luck.
Personally, if I was designing an application like this, I would prefer to generate the ui files myself using a suitable XML library (either Qt's, or one of the several python standard library modules). The structure of a form layout is pretty simple and regular, so the ui files should not be too difficult to replicate. The major benefit of doing things this way is that it allows for complete control over the input and output.
There is a load(), but no save() in the QUiLoader:
http://developer.qt.nokia.com/doc/qt-4.8/quiloader.html#load
The UI file format is documented, and is XML. So you could write your own .UI file generator:
http://developer.qt.nokia.com/doc/qt-4.8/designer-ui-file-format.html
In fact, you could attack this problem the other way around. Instead of generating the dialog using programmatic widget API calls...instead generate a .UI file with XML. Then you can load it in your app or through QtDesigner.
(Depending on what your app is or is intended to do, you might also look into rethinking it as a QtDesigner plug-in...in which case this functionality might come for free.)
I am trying to get Slickedit working with the Qt framework so that I can navigate the codebase easily and because of the other features it provides. To context tag the library I go to Tools > Tag Files, then I right click on C/C++ to add tag file. I name it Qt.vtg and then select the following trees:
C:\Qt\2010.05\qt\src
C:\Qt\2010.05\qt\include
I get context tagging for something, but I can't get context tagging for some scenarios where I normally get it:
When I try to get the parameters for a second pointer, it shows nothing:
oldAddress = ui->addressText->
When I try to complete specific headers it also gives no help
#include <QtCore/ >
I don't know if I am missing a step for context tagging QT, or the additional steps for context tagging QT.
Ted.
You have to provide the include directories of QT for your project, either in your project's properties (Menu Project, Project properties, directories' tab), or in your compiler's properties (Menu Tools, Options, search for "Compiler properties"). This will enable your project to find the include files; the tag file alone doesn't really help, since you may have conflicting tags in the many tag files you could have, so the include files are necessary.
Make sure you have activated all the macros QT provides to your build system. It's been ten years since I used Qt, but IIRC there were several macro defines optionally specified on a compiler command line; make sure SlickEdit knows about them. (Menu Project, Project properties, compile/link tab).
If that's not sufficient, please give more details (where the definition is contained, settings for autocomplete, for context tagging, etc).
Is there a stylesheet available for use in Qt applications (through Qt Creator) that makes your GUI use the stylesheet you see in Qt Creator itself, as well as in AutoCAD and some other applications?
What is the name of that stylesheet or where can I get it? It looks much like the Vista stylesheet though...
And whenever you set a custom stylesheet to your Qt application, will it display the same style on all platforms, or will it still display native GUI parts?
To the people that may want to find out more: The style seems to be called manhattanstyle and extends QWindowsStyle. It is not a css-stylesheet and therefore not just copy and paste to set up. It seems to have some other dependencies in the source code, so I don't know how much it will take to adapt it.
The source is found in the [qt-creator source code]/src/plugins/coreplugin/manhattanstyle.cpp
And btw: if you are running debian/ubuntu: type apt-get source qt-creator to get the source ;)
I can't say as to how you would get style sheets that match Qt Creator or AutoCAD but to answer your other question: When you apply a style sheet, it applies to the object you applied it to, and the child hierarchy of that object. Any widget not addressed by the style sheet in some way will maintain the native look and feel that matches the Style (not style sheet) chosen by Qt as most appropriate for you application based on the user's platform and desktop environment.
yes, somebody has separated it out.
see this Manhattan style