I am creating a plugin for Qt Designer (for now, I'm stuck with Qt 4.8.7). It has a property that represents a directory on the hard drive (its type is QString). I do not want this property to ever be translatable. When working in Qt Designer, I can see in the Property Editor dock window that QObject's objectName
property does what I want, with no sub properties under it. In my plugin, I define a settingsPath
property using the Q_PROPERTY
macro (the same way QObject declares objectName
), but when I edit a widget in Qt Designer and add my plugin widget, the settingsPath
property shows three sub items: translatable, disambiguation, and comment. I don't care about the last two, but I don't want this property to be translatable, and I don't want the user of this plugin to ever have to uncheck "translatable" to use it.
Here is a little more explanation about why the user might need to uncheck translatable: I need to use that property in the Polish event to look up some registry settings. This usually works fine regardless of whether it is translatable or not. However, if the widget is inside a QSplitter, I can see in the generated moc_ file that the polish event of my plugin widget gets called (several layers deep on the stack) when setting percentages on the QSplitter, which is before any of the translation code. This means that the settings are not read in yet at the time of the Polish event on my plugin. (The fact that setupUi() can call ensurePolish() on anything is probably a bug in Qt, but that is a different issue.)
"Translatable" property in Qt Designer is controlled by notr
attribute of stringpropertyspecification
in domXml
of custom widget interface. Link to documentation:
If the attribute is "true", the value is not meant to be translated.
To disable translations for string property exampleProperty
your domXml()
function in QDesignerCustomWidgetInterface
descendant should return something along the lines of:
<ui language="c++"> displayname="MyWidget">
<widget class="mynamespace::MyWidget" name="mywidget"/>
<customwidgets>
<customwidget>
<class>mynamespace::MyWidget</class>
<propertyspecifications>
<stringpropertyspecification name="exampleProperty" notr="true" type="singleline" />
</propertyspecifications>
</customwidget>
</customwidgets>
</ui>