0

I would like to inherit from "QDoubleSpinBox" and add some functionality and add to MainWindow. the code like this compiles fine, but i don't know how to add it/place it on via code MainWindow along the other elements in designer.

.h file:

class DoubleSpinner : public QDoubleSpinBox
    { 
        Q_OBJECT
    public:
        DoubleSpinner (QDoubleSpinBox *parent  = nullptr);



        ~DoubleSpinner(){}

        //Message();


    private:

    };

.cpp file:

DoubleSpinner::DoubleSpinner (QDoubleSpinBox *parent) : QDoubleSpinBox(parent)
{

}

mainwindow.cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
       ui->setupUi(this);

       ui->lineEdit->setText("0.0001");

       //DoubleSpinner ds = new DoubleSpinner;

}

MainWindow::~MainWindow()
{
    delete ui;
}
hyde
  • 60,639
  • 21
  • 115
  • 176
NaturalDemon
  • 934
  • 1
  • 9
  • 21

1 Answers1

0

You need to read this topic from Qt documentation if want to use custom widgets in Qt Designer:

Creating Custom Widgets for Qt Designer

You can also create layouts in Qt Designer and then instantiate and reparent your widgets to those layouts. I recommend you to start learning Qt without using the designer to get familiar with under the hood of Qt. You can use the Qt Designer later whenever you will.

Soheil Armin
  • 2,725
  • 1
  • 6
  • 18
  • 2
    Creating custom plugins for Designer is, 99% of the time, absolutely wrong way to do this. It's a huge amount of work for essentially zero gain... – hyde Oct 27 '19 at 11:39
  • I agree with @hyde. It only makes sense when you are working in a team with separate designers and you have plenty of time and resources to take that path. I personally never used Qt Designer in my 10+ years of using Qt. – Soheil Armin Oct 27 '19 at 11:45