Qt Designer add '&' (ampersand) in text automatically - qt

I am using Qt 5.11.1 on Manjaro Linux.
When I open Qt Designer, create a new dialog and add stuff on the widget, Qt Designer adds '&' (ampersand) in the text in some types of widgets automatically. (Ampersand "&" is shortcut in Qt, commonly referred to as "mnemonic". For example, if text of button is "b&utton", I can click the button with Alt + U. See this answer for more information.) For example, if I create a radio button and set the text to "button", the text will become "b&utton" automatically, and I cannot remove the '&'. What should I do?

Not sure, probably qt_set_sequence_auto_mnemonic function is what you are looking for.
Specifies whether mnemonics for menu items, labels, etc., should be honored or not. On Windows and X11, this feature is on by default; on macOS, it is off. When this feature is off (that is, when b is false), QKeySequence::mnemonic() always returns an empty string.
Note: This function is not declared in any of Qt's header files. To use it in your application, declare the function prototype before calling it.

The workaroud in How to disable automatic mnemonics in a Qt application on KDE? works. Thank you Andrii for providing the link!
The workaroud is to add
[Development]
AutoCheckAccelerators=false
to ~/.config/kdeglobals.
I also found that removing the package kdelibs4support is also a workaround, but some packages might depend on it.

Related

Text from qstring has & [duplicate]

In any Qt application on KDE when I add a QPushButton in designer and check it's text by:
void MainWindow::on_pushButton_clicked()
{
qDebug()<<ui->pushButton->text();
}
The output is preceded by an & :
&PushButton
This behavior does not exist on Windows. It seems that Qt applications on KDE automatically add shortcuts to all push buttons, which is not desired for me. I should note that the ampersands are not created by designer and you can not see them in the.ui file. Actually when the button is added to a widget, an & is placed somewhere in it's text.
Is it possible to disable automatic mnemonics of a Qt application in anyway?
KDEPlatformTheme plugin responsible for it.
A workaround is to add
[Development]
AutoCheckAccelerators=false
to ~/.config/kdeglobals, which prevents KDE from automatically adding accelerators.
Related bug: https://bugs.kde.org/show_bug.cgi?id=337491

How to repaint a widget in QT designer

I am just beginning to learn some programming with QT, and would like to start with the designer portion of QT Creator, before diving into the .cpp, and .h files. I would like to do simple tasks like change the color of a box based on a condition, or perform some arithmetic. But everything I read describes how to the change the code, not do it in the UI editor. Even the QT Designer manual gives no demonstration of how to create a simple calculator in Designer. They only show the code (http://doc.qt.io/qt-5/designer-using-a-ui-file.html). I've loaded the project from the links at the bottom of this page: http://doc.qt.io/qt-5/qtdesigner-calculatorform-example.html, but I'm still stumped as to how it does the arithmetic from looking at the UI editor. I don't see any signals/slots indication an addition on the numbers in the spin boxes. Nor, do I see anything in the properties of the Output QLabel that makes it the sum of Input1 and Input2.
And just to add another level to this simple example, how could I change the color of the output box if a condition is met? Let's just say if the output is larger than 10, make the box blue. I see the palette in the Properties box, but how do I make it conditional, staying within the Designer portion of the Creator application?
Thanks!
You're searching for a way to execute simple code/actions directly from within qt-designer, without using any code behind.
That's not possible, if you use qt-designer and .ui files.
You can connect slots to signals directly from the designer, but you have to implement those slots in your *.cpp file.
If you want to mix the UI design with your application logic take a look at QML.

How to add short-key for "Add Definition in class.cpp" in Qt Creator

When you define a member function in a class Interface in Qt creator you can right click on the function prototype and select Refactor->Add Definition in YouClass.cpp . But this will be really handy If you can set a shortcut for it. I couldn't find it in options->shortcut section.
For example in Visual Assist you can press ALT+SHIFT+Q.
You can press Alt+Enter to open a context menu that contains refactoring actions, which are available at the current cursor position.
This is also mentioned in the documentation under Refactoring C++ Code
Maybe a solution with a macro or something in that direction exists as well.
As proposed by #Robin Karlsson:
You can press Alt+Enter to open a context menu that contains refactoring actions available in the current cursor position.
As mentioned by #Dmitry Volosnykh, the above appears in the documentation (more concretely at Applying Refactoring Actions
)

Qt can I drag and drop from widget to Qwebkit?

I'm developing simple HTML editor and I like to be able to drag and drop from a button that for example represent HTML text line and in the Qwebkit the HTML text line will be created does Qt support such action?
How should I approach such thing?
I believe it does, yes.
What you need to do is set the mime type of your drag event. See here for details. Then on the webkit side, you can read the drops mime type to see what it was.
You can then try one of the following approaches:
Subclassing QWebView to implement dragEnterEvent and dropEvent. You can use event->pos() in the dropEvent to get the position where the drop occured.
Implementing the drop in javascript within your page, eg setting up an event listener for drops or however its done (I've never tried this).

Best Qt Widget to use for properties window?

I want a widget like the properties window in Visual Studio or NetBeans. It basically has two columns: the name of the property on the left, and the value on the right. The value needs to be able to be restricted to certain types, like 'bool' or 'float' (with valid ranges), but should also support more complex types (perhaps requiring a popup dialog when clicked, and then it can just display a toString() version in the window. I'm sure I can add most of those features myself, but what's the best base widget to start with?
Oh... grouping of properties is good too (like a tree I guess). And property editing should invoke a callback (send a signal).
Qt designer has properties exactly like you want. They are most likely implemented with QTreeView. You can always look at the source code.
QTreeView or QTableView. Do all (ok, most) of the heavy lifting with a specialized model that handles all of your type restrictions and what-not. Check out delegates as well.
Here's a link led to github, it might be useful.
another userful link

Resources