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.)
Related
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....
I am creating a free application with pyqt5.
In this application, i need to give the users the possibility to type custom python scripts.
I don't want to develop a whole python syntax parser and provide autocompletion as it seems a long process and the scripting is not the most important part of the application.
I ask whether vscode (or other script editing tool) offer the possibility to embed a special editor as a QWidget inside an application that provides syntax analysis and autocompletion.
Thanks for help
Yes, there is: QScintilla, the Qt port of scintilla, a library for text editing oriented to source code editing.
This is how you set up a basic editor with minimal syntax highlighting:
class Editor(Qsci.QsciScintilla):
def __init__(self):
super().__init__()
font = self.font()
font.setFamily('mono')
self.setFont(font)
# create a "Lexer", which is what allows syntax highlighting
# within the editor; the following is the class for python
# syntax, but there are other classes for different languages
lexer = Qsci.QsciLexerPython()
lexer.setDefaultFont(font)
self.setLexer(lexer)
You can find the documentation at the official site
Is it mandatory to embbed the editor inside your application?
Maybe you could make your app open a system editor instead and let the user choose the tool of his preference.
I'm writing some input bindings in Shiny, and want to build my functions into a package. The problem now is input bindings requires javascript code which is usually located in the www directory in the application directory, so the user need to copy the javascript file into his/her www every application he/she requires the package and use the input bindings.
And I want when the user of this package require()ed this package, the corresponding input binding jQuery definitions are automatically loaded with the app just as the native binding definitions are. Or does anyone knows other solutions for this situation.
You can place the javascript code in the inst folder in your package and declare that folder as a dependency. There are probably other ways, perhaps even better ways, but you can see as an example how I did this in my package. I created a colourInput widget that needed two javascript files: one for the input bindings, and one for the actual javascript library for the button.
Here is the folder where my javascript and css is kept (notice how it's under inst/www/shared/colourpicker), and here is the code I use to declare the javascript/css files as dependencies, and at the last line I attach the javascript/css dependencies to the button HTML.
It took me a while to understand how to implement this, but this is a working example, so you can look at this real code and follow a similar approach.
I just started using the feature that allows you to compile all TypeScript to a single .js file. The problem I ran into, as you'd expect, is that the entire .js file is executed, and not just the module(s) that I need my page to execute.
Are there any built in utilities that allow me to specify this? If not, what else can I use? I work with a team using source control, so a solution like a NuGet package that can automatically get installed for my colleagues when they use the project is preferable.
The problem I ran into, as you'd expect, is that the entire .js file is executed, and not just the module(s) that I need my page to execute.
You shouldn't have code randomly put at a global level. The global level of your code be just functions and class that are inert by them selves.
Then have the UI call these functions / classes based on current html. Some UI framework (like angular) can help you do this seperation in a neat way (example : https://www.youtube.com/watch?v=Km0DpfX5ZxM&feature=youtu.be)
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