How to get promoted widget to show?
-
I am trying to do a simple demo for myself however I cannot get my slider or my qspinbox to show up.
I created a simple getter and setter within a custom Slider and SpinBox class:
#include <QObject> #include <QWidget> #include <QSlider> class Slider : public QSlider { Q_OBJECT public: Slider(QWidget *parent = nullptr); void updateValue(int value) { this->setValue(value); } int get() const { return this->value(); } };
I then add a QSlider onto the QtDesigner and promote the QSlider to my Slider class.
In my MainWindow.h, I simply create a Slider as a private member like such Slider newSlider; In MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), newSlider(parent) { ui->setupUi(this); }
However, when I run the program, the QSlider does not show up. What am I doing wrong?
-
@Sailanarmo
You can promote your class directly on Qt Designer.
-
Hi
First of all.
You dont need to make a variable for it. ( the newSlider(parent) )
as the widget you promoted is now the slider and can be accessed via
ui->slidername ( same name as the promo widget)Also, if you see nothing, i would guess on that for
Slider(QWidget *parent = nullptr); in cpp, you do not call base class to set it up?Slider::Slider(QWidget *parent) : QSlider(parent) {
...
} -
@KillerSmath This is exactly what I did. However it still isn't showing up when I run the program.
-
Hi
Do you call base class in your constructor ? -
Heh yep, also due no error is shown, its simply not there.
Did you noice that its in UI and no need to add extra variable for it ?