Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6388991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:20:55+00:00 2026-05-25T03:20:55+00:00

I want to create a custom widget that contains a QSpinBox. I want the

  • 0

I want to create a custom widget that contains a QSpinBox. I want the custom widget to expose some of QSpinBox’s properties as its own so it can work conveniently in Designer.

Is there a convenient way to do this kind of property proxying in Qt?

I want to reiterate that the relationship between my custom widget and the QSpinBox is containment, not inheritance. I am using pyqt, but will happily accept a pure qt answer.

To clarify, I want to create variations of standard widgets that have some extra decorations. For example, I will be adding a toggleable icon to sit beside my QSpinBox. However I still want to be able to configure the QSpinBox in designer (ie, set the suffix, upper and lower limits, increment, etc).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:20:56+00:00Added an answer on May 25, 2026 at 3:20 am

    Alrite, so here’s a way to do it.

    It’s better than writing a function manually for each property. Basically, you write a macro that expands the code for you.
    I have a doubleSpinBox in my widget and its value is changed whenever I change the property. And you emit a signal whenever the property changes, which is connected to the doubleSpinBox->setValue(). Tested and works perfectly.
    Complete code at this link.

    #ifndef MYWIDGET_H_
    #define MYWIDGET_H_
    
    #include <QtGui/QWidget>
    #include <QtGui/QLabel>
    #include "ui_mywidgetform.h"
    
    #define MYPROPERTY_SET_FUNC(_PROPCLASS_, _PROP_PARAM_NAME_, _PROP_SET_FUNC_NAME_, _PROP_NOTIFY_) \
      void _PROP_SET_FUNC_NAME_(_PROPCLASS_ _PROP_PARAM_NAME_) \
      { \
        emit _PROP_NOTIFY_(_PROP_PARAM_NAME_); \
      }
    
    #define MYPROPERTY_GET_FUNC(_PROPCLASS_, _PROP_READ_FUNC_NAME_, _PROP_VARIABLE_)\
      _PROPCLASS_ _PROP_READ_FUNC_NAME_() const  \
      { return _PROP_VARIABLE_; }
    
    class MyWidget : public QWidget
    {
      Q_OBJECT
    
    public:
      MyWidget(QWidget *parent = 0);
      ~MyWidget();
      enum Accuracy {Good, Bad};
    
    signals:
      void doubleSpinBoxValueChanged(double);
      void accuracyChanged(Accuracy);
    
    private:
        Q_PROPERTY(Accuracy accuracy READ accuracy WRITE setAccuracy NOTIFY accuracyChanged)
        Q_PROPERTY(double doubleSpinBoxValue READ doubleSpinBoxValue WRITE setDoubleSpinBoxValue)
    
    private:
      Accuracy m_accuracy;  //custom class property
      Ui::Form m_ui;
    
    public:
      //Getter functions
      MYPROPERTY_GET_FUNC (double, doubleSpinBoxValue, m_ui.doubleSpinBox->value())
      MYPROPERTY_GET_FUNC (Accuracy, accuracy, m_accuracy)
      //Setter functions
      MYPROPERTY_SET_FUNC(Accuracy, accuracy, setAccuracy, accuracyChanged)
      MYPROPERTY_SET_FUNC(double, doubleSpinBoxValue, setDoubleSpinBoxValue, doubleSpinBoxValueChanged)
    
    };
    
    #endif // MYWIDGET_H_
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create an Android project for build my custom widget, and I want to
i want create a custom json data from the mssql 2008 results so that
I want to create a custom set that will automatically convert objects into a
I want to create a custom style for an activity that will look like
Trying to create a widget with custom fonts, but read that widget doesn't support
I want to create a custome widget. Please help by giving some idea. My
I want to create custom WPF control that has a single child control inside.
I want to create custom ImageButton, but to work like on/ off button. On
I am trying to create a custom Dojo ValidationIdBox widget that inherits from ValidationTextBox.
I want to create custom button and I need it to be circle. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.