Results 1 to 20 of 28

Thread: How to change widget shape in QtDesigner ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    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 ?

    The documentation for Q_ENUMS() says it is obsolete and that you should use Q_ENUM() instead. It is possible that the version of Qt Designer you are using depends on the enum being registered with Qt's meta type system. Q_ENUM() must be placed in the code after the enum has been declared.

    Qt Code:
    1. #pragma once
    2.  
    3. #include <Qt>
    4. #include <QtWidgets/QWidget>
    5. #include <QtUiPlugin/QDesignerExportWidget>
    6.  
    7.  
    8. // My Qt designer widget plugin class
    9.  
    10. class QColor;
    11.  
    12. class QDESIGNER_WIDGET_EXPORT QLed : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. Q_PROPERTY(bool value READ value WRITE setValue)
    17. Q_PROPERTY(ledColor onColor READ onColor WRITE setOnColor)
    18. Q_PROPERTY(ledColor offColor READ offColor WRITE setOffColor)
    19. Q_PROPERTY(ledShape shape READ shape WRITE setShape)
    20.  
    21. public:
    22. explicit QLed(QWidget *parent = 0);
    23.  
    24. bool value() const { return m_value; }
    25.  
    26. enum ledColor { Red = 0, Green, Yellow, Grey, Orange, Purple, Blue };
    27. Q_ENUM (ledColor)
    28.  
    29. enum ledShape { Circle = 0, Square, Triangle, Rounded };
    30. Q_ENUM (ledShape)
    31.  
    32. ledColor onColor() const { return m_onColor; }
    33. ledColor offColor() const { return m_offColor; }
    34. ledShape shape() const { return m_shape; }
    35.  
    36. public slots:
    37. void setValue(bool);
    38. void setOnColor(ledColor);
    39. void setOffColor(ledColor);
    40. void setShape(ledShape);
    41. void toggleValue();
    42.  
    43. signals:
    44. void shapeChanged(ledShape);
    45.  
    46. protected:
    47. bool m_value;
    48.  
    49. ledColor m_onColor, m_offColor;
    50.  
    51. int id_Timer;
    52.  
    53. ledShape m_shape;
    54.  
    55.  
    56. void paintEvent(QPaintEvent *event) override;
    57. };
    To copy to clipboard, switch view to plain text mode 

    For your example with the 5 LEDs, can you post the XML .ui file that Qt Designer creates for this widget? In Qt Designer, be sure to select different shapes for the LEDs even if Qt Designer shows them all as circles.
    Last edited by d_stranz; 30th April 2023 at 16: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.

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.