Qt Creator open ui.qml file in editor by default - qt

In Qt creator whenever you open a ui.qml file by double clicking or CTRL + TAB the file normally opens in design mode. To see the code, you need to hit ESC to go the text editor. I want that the ui.qml files should open by default in the editor. How can I do that in settings?

In Qt Creator:
Tools >>> Options;
Open Environment;
Go to MIME Types;
Find (by filter, for ex.) application/x-qt.ui+qml;
Delete or change Pattern field in Details.

If you want to edit .ui.qml files by hand, don't use .ui.qml files?
These are made to be edited by the designer and are limited to a small subset of QML because of that.
Just use the normal .qml extension in this case.
More info on QML UI files here.

Related

No headers or source files in QT creator

I'm having a problem with creating new header and source files in QT. I can only add new files to the build, it's grayed for the "main" project as you can see below.
I can create them specifically for the build and they only appear once in the documents area. There is no header tree branch. After I close qt I have to create new ones. I want them to appear in the tree and be connected with the main project. I have "hide source and headers files" option off.
I've obviously tried creating them the way it was shown on the yt. I've searched through settings but didn't found anything I could use.
You will have to add the files manually in CMake.
Go to File>New File and select what type of file you want. Typically it will be a source, header, or both (class).
Edit the CMakeLists.txt file:
qt_add_executable(myapp
myapp.qrc
main.cpp
new_file.cpp
new_file.h
)
Resources like .qml files and things like images (*.png *.jpg) are added in the myapp.qrc file

Removing QActions from the ui_mainwindow.h file

My app was started (by someone else) in Qt Designer. For a number of reasons I've decided to put the main form gui together in C++. In the designed I deleted all the gui widgets and removed the menu items from the object tree.
Having got the layout how I want it I started adding in the actions to find that they are still declared in the ui_mainwindow.h file.
Is it safe to manually remove the action declarations from this file? Or is there a way of doing this through Qt designer?
Open your *.ui file in the designer. In the lower right corner you'll see Action Editor. Actions can be deleted from there.

Qt Linguist: translation of text changed dynamically in tr()

I am using qt linguist and qt 5.2. I have a problem that when I add something to .ui files I can see it after lupdate in ts file but when I change name of this button dynamically in my code like:
ui->label->setText(tr("foo"));
I can't see it in ts file, is it possible to make translation in that case? How I can do this?
Basically, tr() can be detected anywhere in the codes.For ui files, linguist would detect the changes immediately, however in codes I encounterd the same problem.
Based on my experience, try to reBuilt/qmake it.
(I am using Qt4.8 & 5.1.)

Hand editing .ui files inside Qt editor

I've been tweaking my .ui files by hand a lot recently and I'm curious, does anyone know how to turn off read only mode for .ui files in Qt Creator?
In case that's not immediately clear, what I mean is that .ui files (by default) are view-able inside Qt Creator but not write-able... and it's a minor nuisance to go boot up some other xml editor :/
Thanks!
In the context menu of any .ui file in the project explorer, click Open With and then Plain Text Editor. This gives you the same editor but with write mode.
Note that the disabled write mode for ui files when double clicking and changing to "Edit" mode rather than "Design" mode isn't a bug but a feature. Editing ui files by hand can destroy your file. At least, this is what the Qt guys think...

How can files and classes be renamed in Qt Creator?

How do I rename files and classes (declaration, implementation and uses) in Qt Creator 2.0?
I can't find such feature in there.
There is no such feature in Qt Creator :(
This is what you can do:
To rename files:
close your project
rename files in Windows Explorer or some other tool
open project
update *.pro file, list *.h files in headers, *.CPP files in sources, *.ui files in forms
update all *.ccp files in the #include section to include proper files
To change class names you can use the Ctrl + Shift + R feature that changes class names in header files and source files.
If you also want to rename a form and along with its class, you have to edit your name.ui file and change the widget name and class to the new corresponding value.
You also need to rename some things in your name.h file.
namespace Ui {
class NewValueHere;
}
private:
Ui::NewValueHere* mUI;
In your name.cpp file you also have to adjust the call of creating your mUI.
mUI(new Ui::NewValueHere)
Personnally I needed to do something more.
I renamed my class "Form" to "MainWindow", and I had to go in the directory "build-yourproject...-Debug\ui_mainwindow.h" and replace every "Form" with "MainWindow" (Ctrl+f) and then it worked.
EDIT: This was a manual solution that changes a file that is re-loaded at every build, so this change is automatically lost. The right solution is to go in Qt Creator and in the upper-right corner, under the name "Object", you should have the name of your class, that is what you need to change.

Resources