Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by uwestoehr »

I noticed an issue in FC's definition of Gui::PrefUnitSpinBox and Gui::QuantitySpinBox.
They don't inherit e.g. the alignment property from QAbstractSpinBox. Other spin boxes have this and therefore support these useful settings:
QAbstractSpinBox properties
QAbstractSpinBox properties
qtcreator_GHqTPR0N77.png (7.84 KiB) Viewed 1426 times

Is it OK to add this inheritance? I would e.g. like to set the alignment for all spin boxes in a dialog, not only for the Q spin boxes.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by uwestoehr »

uwestoehr wrote: Thu Mar 26, 2020 11:13 pm They don't inherit e.g. the alignment property from QAbstractSpinBox.
Hmm, looking in the code, they seem to do but Qt designer doesn't not recognize them. I can also not find anything about this in
https://wiki.freecadweb.org/Developer_hub
I also searched the Wiki.

So how can I tell Qt designer how to handle the GUI:: widgets?
User avatar
wandererfan
Veteran
Posts: 6270
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by wandererfan »

uwestoehr wrote: Thu Mar 26, 2020 11:13 pm I noticed an issue in FC's definition of Gui::PrefUnitSpinBox and Gui::QuantitySpinBox.
They don't inherit e.g. the alignment property from QAbstractSpinBox. Other spin boxes have this and therefore support these useful settings:
They already inherit QAbstractSpinBox. Maybe your plugin (libFreeCAD_widgers.so on linux. don't know about Win) is not up to date?

see QuantitySpinBox.h

Code: Select all

class GuiExport QuantitySpinBox : public QAbstractSpinBox, public ExpressionBinding
and in Qt5 Designer:
GQSBInherit.png
GQSBInherit.png (70.71 KiB) Viewed 1419 times
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by wmayer »

uwestoehr wrote: Thu Mar 26, 2020 11:28 pm
uwestoehr wrote: Thu Mar 26, 2020 11:13 pm They don't inherit e.g. the alignment property from QAbstractSpinBox.
Hmm, looking in the code, they seem to do but Qt designer doesn't not recognize them. I can also not find anything about this in
https://wiki.freecadweb.org/Developer_hub
I also searched the Wiki.

So how can I tell Qt designer how to handle the GUI:: widgets?
It's not a matter of inheritance but a matter of the lack of the Qt plugin. It's possible to use custom FreeCAD widgets in the designer without the FreeCAD plugin but its usage is limited. If you look at the XML code inside a .ui file and search for QuantitySpinBox you can see that adding custom properties is possible and at the end you will see there is a block:

Code: Select all

  <customwidget>
   <class>Gui::QuantitySpinBox</class>
   <extends>QWidget</extends>
   <header>Gui/QuantitySpinBox.h</header>
  </customwidget>


The problem here is that in real C++ QuantitySpinBox inherits from QAbstractSpinBox but it's not possible to say so in the .ui file because QAbstractSpinBox is an abstract class and cannot be instantiated. If you try it anyway the designer raises an error when loading the modified .ui file.

To have full access over QuantitySpinBox in Qt designer then the only option is to build the FreeCAD plugin and put it into the plugins directory of your Qt installation.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by uwestoehr »

wmayer wrote: Fri Mar 27, 2020 7:33 am To have full access over QuantitySpinBox in Qt designer then the only option is to build the FreeCAD plugin and put it into the plugins directory of your Qt installation.
I want to do so and document this in my build on Windows instructions in the Wiki. However, it is not yet clear to me how this is done.
In my build folder I find the folder "QtUiPlugin" that contains custom Qt designer widgets. But how do I say Qt designer to use them?
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by wmayer »

You must build this plugin: https://github.com/FreeCAD/FreeCAD/tree ... ins/widget

On Windows open command line shell from within VS or of the VS installation in the start menu. Then cd to the directory and enter

Code: Select all

qmake plugin.pro
nmake -f Makefile.Release
Copy the dll to the designer sub-directory of the plugins folder of Qt.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by uwestoehr »

wmayer wrote: Fri Mar 27, 2020 1:44 pm You must build this plugin: https://github.com/FreeCAD/FreeCAD/tree ... ins/widget

On Windows open command line shell from within VS or of the VS installation in the start menu. Then cd to the directory and enter

Code: Select all

qmake plugin.pro
nmake -f Makefile.Release
Copy the dll to the designer sub-directory of the plugins folder of Qt.
Thanks. However, I am not able to build this, because despite I am in the VS shell for x64, it tells me that the target destination is x86:
cmd_ay0SL85Rse.png
cmd_ay0SL85Rse.png (48.08 KiB) Viewed 1329 times

I cannot find a way to tell qmake and nmake to use the x64 version.
User avatar
wandererfan
Veteran
Posts: 6270
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by wandererfan »

uwestoehr wrote: Fri Mar 27, 2020 3:21 pm I cannot find a way to tell qmake and nmake to use the x64 version.
do you have both Qt4 and Qt5 installed? If so, you may need to point at the Qt5 version of qmake.

I've run into this on Linux, don't know if it applies to Win.
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by uwestoehr »

wandererfan wrote: Fri Mar 27, 2020 4:21 pm do you have both Qt4 and Qt5 installed?
I only have Qt 5.12.1 installed here.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Gui::QuantitySpinBox miss QAbstractSpinBox inheritance

Post by wmayer »

You can also try: qmake -t vclib plugin.pro to create a VS project.
Post Reply