Results 1 to 20 of 28

Thread: How to change widget shape in QtDesigner ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: How to change widget shape in QtDesigner ?

    Quote Originally Posted by d_stranz View Post
    Your UI file:

    Qt Code:
    1. <widget class="Led" name="led_1">
    2. <widget class="Led_0_6_1" name="led_0_6_1">
    3.  
    4. ...
    5.  
    6. <customwidget>
    7. <class>Led</class>
    8. <extends>QWidget</extends>
    9. <header>Led.h</header>
    10. </customwidget>
    11.  
    12. <customwidget>
    13. <class>Led_0_6_1</class>
    14. <extends>QWidget</extends>
    15. <header>Led_0_6_1.h</header>
    16. </customwidget>
    To copy to clipboard, switch view to plain text mode 

    Your original code:

    Qt Code:
    1. QString QLedPlugin::name() const
    2. {
    3. return u"QLed"_s;
    4. }
    5.  
    6. QString QLedPlugin::domXml() const
    7. {
    8. return uR"(
    9. <ui language="c++">
    10. <widget class="QLed" name="qLed">
    11. )"
    12.  
    13. R"(
    14. <property name="geometry">
    15. <rect>
    16. <x>0</x>
    17. <y>0</y>
    18. <width>50</width>
    19. <height>50</height>
    20. </rect>
    21. </property>
    22. ")
    23.  
    24. R"(
    25. <property name="toolTip">
    26. <string>Binary Led</string>
    27. </property>
    28. <property name="value">
    29. <bool>false</bool>
    30. </property>
    31. <property name="whatsThis">
    32. <string>Led widget</string>
    33. </property>
    34. <property name="onColor">
    35. <enum>QLed::Red</enum>
    36. <enum>QLed::Green</enum>
    37. <enum>QLed::Yellow</enum>
    38. <enum>QLed::Grey</enum>
    39. <enum>QLed::Orange</enum>
    40. <enum>QLed::Purple</enum>
    41. <enum>QLed::Blue</enum>
    42. </property>
    43. <property name="offColor">
    44. <enum>QLed::Grey</enum>
    45. </property>
    46. <property name="shape">
    47. <enum>QLed::Circle</enum>
    48. <enum>QLed::Square</enum>
    49. <enum>QLed::Triangle</enum>
    50. <enum>QLed::Rounded</enum>
    51. </property>
    52. </widget>
    53. </ui>
    54. )"_s;
    55. }
    56.  
    57. QString QLedPlugin::includeFile() const
    58. {
    59. return u"qled.h"_s;
    60. }
    To copy to clipboard, switch view to plain text mode 

    You're wasting my time here, if the code you are now using is nothing like the code you originally posted. How is anyone supposed to help you determine what is wrong when your are looking at oranges while we are looking at apples?
    You are absolutely right, I apologize. Only in the meantime I've been trying to get on with the code and try some changes. It just changed the name from QLed to Led_0_6_1, but it's still the same. Sorry, I forgot to tell you earlier...

    I managed to solve the problem by editing the Test.ui file of my widget by hand, modifying it like this:
    Qt Code:
    1. ...
    2. <property name="onColor">
    3. <enum>Led_0_6_1::Orange</enum>
    4. </property>
    5. ...
    6. <property name="shape">
    7. <enum>Led_0_6_1::Triangle</enum>
    8. </property>
    9. ...
    To copy to clipboard, switch view to plain text mode 
    this displays the right shape of the widget. However, this solution doesn't satisfy me much, as I wanted to do it in the Qt Designer environment through the properties of my widget.
    Last edited by giorgik; 30th April 2023 at 19:28.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,325
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change widget shape in QtDesigner ?

    Please do not reply by quoting my entire response. It makes the thread extremely long and difficult to read. Just click Reply, then add QUOTE tags for specific things. Thanks.

    I wanted to do it in the Qt Designer environment through the properties of my widget.
    OK, I am pretty sure the problem is in the domXml() method of your plugin. The XML code is supposed to be a template that Qt Designer uses when writing the widget's specification to the .ui file. I think your mistake is including all of the enum values in this XML, when there should only be one as a placeholder. So your domXml() should look like this:

    Qt Code:
    1. QString QLedPlugin::domXml() const
    2. {
    3. return uR"(
    4. <ui language="c++">
    5. <widget class="QLed" name="qLed">
    6. )"
    7. R"(
    8. <property name="geometry">
    9. <rect>
    10. <x>0</x>
    11. <y>0</y>
    12. <width>50</width>
    13. <height>50</height>
    14. </rect>
    15. </property>
    16. ")
    17. R"(
    18. <property name="toolTip">
    19. <string>Binary Led</string>
    20. </property>
    21. <property name="value">
    22. <bool>false</bool>
    23. </property>
    24. <property name="whatsThis">
    25. <string>Led widget</string>
    26. </property>
    27. <property name="onColor">
    28. <enum>QLed::Red</enum>
    29. </property>
    30. <property name="offColor">
    31. <enum>QLed::Grey</enum>
    32. </property>
    33. <property name="shape">
    34. <enum>QLed::Circle</enum>
    35. </property>
    36. </widget>
    37. </ui>
    38. )"_s;
    39. }
    To copy to clipboard, switch view to plain text mode 

    Qt Designer will understand from your Q_ENUM() and Q_PROPERTY() definitions what are the allowed values to substitute for the placeholder values in the template.

    The Qt Designer UI file format is here. Near the bottom of the page is the specification for the Property type, which specifies what the <property> element can contain.

    Qt Code:
    1. <xs:complexType name="Property">
    2. <xs:choice>
    3. <xs:element name="bool" type="xs:string" />
    4. <xs:element name="color" type="Color" />
    5. <xs:element name="cstring" type="xs:string" />
    6. <xs:element name="cursor" type="xs:integer" />
    7. <xs:element name="cursorshape" type="xs:string" />
    8. <xs:element name="enum" type="xs:string" />
    9. <xs:element name="font" type ="Font" />
    10. <xs:element name="iconset" type="ResourceIcon"/>
    11. <xs:element name="pixmap" type="ResourcePixmap" />
    12. <xs:element name="palette" type="Palette" />
    13. <xs:element name="point" type="Point" />
    14. <xs:element name="rect" type="Rect" />
    15. <xs:element name="set" type="xs:string" />
    16. <xs:element name="locale" type="Locale" />
    17. <xs:element name="sizepolicy" type="SizePolicy" />
    18. <xs:element name="size" type="Size" />
    19. <xs:element name="string" type="String" />
    20. <xs:element name="stringlist" type="StringList" />
    21. <xs:element name="number" type="xs:integer" />
    22. <xs:element name="float" type="xs:float" />
    23. <xs:element name="double" type="xs:double" />
    24. <xs:element name="date" type="Date" />
    25. <xs:element name="time" type="Time" />
    26. <xs:element name="datetime" type="DateTime" />
    27. <xs:element name="pointf" type="PointF" />
    28. <xs:element name="rectf" type="RectF" />
    29. <xs:element name="sizef" type="SizeF" />
    30. <xs:element name="longlong" type="xs:long" />
    31. <xs:element name="char" type="Char" />
    32. <xs:element name="url" type="Url" />
    33. <xs:element name="uint" type="xs:unsignedInt" />
    34. <xs:element name="ulonglong" type="xs:unsignedLong" />
    35. <xs:element name="brush" type="Brush" />
    36. </xs:choice>
    37. <xs:attribute name="name" type="xs:string" />
    38. <xs:attribute name="stdset" type="xs:integer" />
    39. </xs:complexType>
    To copy to clipboard, switch view to plain text mode 

    The first part is an <xs:choice> element, which means that only one of the elements listed can appear in the <property> element. In other words, listing more than one <enum> entry violates the <ui> XML specification. So Qt Designer imported your plugin, but probably ignored the incorrect parts of your domXml().
    Last edited by d_stranz; 1st May 2023 at 05:48.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change widget shape in QtDesigner ?

    I understand. Thank you for the explanations. I will look at the document you indicated to me. So to solve my problem, that is to be able to select an item from the shape field list and keep that item as a choice, what should I do ?
    Last edited by giorgik; 1st May 2023 at 11:51.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,325
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change widget shape in QtDesigner ?

    to be able to select an item from the shape field list and keep that item as a choice, what should I do ?
    I think all you need to do is to substitute the domXml() implementation from my last reply and it should all work with the original code you posted (Q_ENUM() instead of Q_ENUMS() of course). Qt Designer should match up the entries from your QLed enum{} lists and convert them to property value choices in the Designer. With the correct XML for the domXml() template, it will substitute the changes when it generates the .ui file for your widget form.

    However, for the offColor property, since you have defined this to us the same enum type as onColor, all of the colors will be available to choose from, not only Grey. If all you will allow is Grey, then it doesn't need to be a user-configurable property at all. However, I can think of using QLed not as an on / off indicator, but as OK / not OK using Green and Red so having a choice would be better.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change widget shape in QtDesigner ?

    Quote Originally Posted by d_stranz View Post
    I think all you need to do is to substitute the domXml() implementation from my last reply and it should all work with the original code you posted (Q_ENUM() instead of Q_ENUMS() of course). Qt Designer should match up the entries from your QLed enum{} lists and convert them to property value choices in the Designer. With the correct XML for the domXml() template, it will substitute the changes when it generates the .ui file for your widget form.
    I already tried with changing the domXml like you said, but nothing changes. The .ui file always remains the same without having the new settings. I do not know what to do...

    I know I'm asking too much, but could you give me your example project, simple simple with the voice selection feature like in my case? It's the only way to see what I forgot to do or if instead it's a problem related to using Qt6.5 in Visual Studio C++ 2022.

    This was an old project of mine done directly in Qt4.8 using MinGw as compiler and it worked perfectly. Now that I've got it back but using Qt6.5 and Visual Studio C++ 2022, it doesn't work anymore :-(

    In practice, it seems that the item I select in the properties panel of my widget in QtDesigner does not take it and does not update the .ui file
    Last edited by giorgik; 1st May 2023 at 18:10.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,325
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change widget shape in QtDesigner ?

    I know I'm asking too much, but could you give me your example project
    Please make a ZIP file of all of your plugin and QLed code, including the SVG files used for drawing the LEDs - basically, everything I need to build your plugin and use it. Source code only, no compiled binary files. I don't have time to create a new plugin, but I can work on your code to try to get it working. You can attach the ZIP file to a reply in this forum.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change widget shape in QtDesigner ?

    Quote Originally Posted by d_stranz View Post
    Please make a ZIP file of all of your plugin and QLed code, including the SVG files used for drawing the LEDs
    OK, below I put the attachment of the project.Led.zip

  8. #8
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change widget shape in QtDesigner ?

    In the ui_TestLed.h should I vary the value passed to setProperty( ):

    led_0_6_3->setProperty("shape", QVariant::fromValue(Led_0_6_1::Circle));

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,325
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change widget shape in QtDesigner ?

    OK, thanks for the code. I did not make many changes to it except to change the Qt::StringLiterals to ordinary strings since I am using Qt 5 and this is not supported. I also found I needed to add QDESIGNER_EXPORT_WIDGETS in the project settings when building the plugin. (Led_6_0_1 -> Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions).

    I designed a simple dialog widget to test the LED widget. The dialog has 5 LED widgets, with different properties set in Qt Designer. There are three push buttons. The first (Toggle LEDs) changes the on / off state for each LED. The second (Change Shapes) sets a new shape for each LED using the setShape() property. The third button (Change Colors) sets new on / off colors for each LED using setOnColor() and setOffColor(). These changes are implemented using a set of simple QLists whose contents are rotated with each click.

    The test program demonstrates that setting shape, color, and value properties works both in Qt Designer (with correct values in the .ui file) and at run-time.

    TestLed.png

    I have attached a ZIP file with the code. I did not include the VS project files since those were changed for Qt 5 and won't apply for you and Qt 6. Just copy the source files. The test project needs to link with your plugin .lib file and include Qt core, gui, widgets, and svg in the configuration settings. The plugin .dll file must be in your path or where the program can load it at runtime.

    Led.zip

    It is probably not correct to have the code for the LED widget inside of the Qt Designer plugin itself. This means any application you write has to link to the plugin library. That is not right. You should separate the code for the widget from the code for the plugin, and create a LED DLL and a plugin DLL. The plugin DLL is linked to the LED library, and you must put the LED DLL where Qt Designer can find it. When you write an application, you should be linking only to the LED .lib and installing the LED DLL with your application.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. #10
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: How to change widget shape in QtDesigner ?

    Thank you for your time for me, I copied your files to my project. Well, starting the test program, using the buttons everything works fine, while in Qt Designer, it still doesn't update the shape of the widget when I change the shape property. It's really a mystery...
    Do you use the Qt Creator environment directly for the modifications you have made ?
    So you always compile inside Qt Creator ?
    Which compiler do you use MinGW or Visual C++ ?
    Last edited by giorgik; 2nd May 2023 at 21:30.

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,325
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change widget shape in QtDesigner ?

    while in Qt Designer, it still doesn't update the shape of the widget when I change the shape property. It's really a mystery...
    It works fine for me, using Qt Designer 5.15.3.

    Test1.pngTest3.pngTest2.pngTest4.png

    If you still have a copy of Qt5 somewhere, copy your DLL into the plugins\designer directory and run the designer.exe you can find in the bin directory. Open the UI file and see what it looks like.

    Edit: Do the colors change when you select different choices in Qt Designer? If not, I think that maybe Qt Designer is using the qled.png icon and not the actual widget. Are you linking your plugin DLL with QtSvg? It is possible that your version of Qt Designer was not built with SVG support linked in, so your SVG resources aren't loading. Try copying the Qt6Svg.dll file into the plugins\designer directory.
    Last edited by d_stranz; 2nd May 2023 at 21:45.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  12. #12
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change widget shape in QtDesigner ?

    Do you use the Qt Creator environment directly for the modifications you have made ?
    So you always compile inside Qt Creator ?
    Which compiler do you use MinGW or Visual C++ ?

Similar Threads

  1. QCursor change shape in Qt 5
    By cic1988 in forum Qt Programming
    Replies: 5
    Last Post: 4th March 2015, 20:49
  2. Can I change the shape of the form in QML?
    By chong_kimkeang in forum Newbie
    Replies: 1
    Last Post: 7th November 2012, 17:51
  3. how to change shape of Qwidget??
    By anupamgee in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2009, 09:54
  4. Change the shape of a frame.
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2007, 06:40
  5. How to change shape fast
    By nileshsince1980 in forum Qt Programming
    Replies: 9
    Last Post: 18th October 2007, 05:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.