Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get promoted widget to show?

How to get promoted widget to show?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 7.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sailanarmo
    wrote on last edited by
    #1

    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?

    KillerSmathK 1 Reply Last reply
    0
    • S Sailanarmo

      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?

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @Sailanarmo
      You can promote your class directly on Qt Designer.
      0_1556744473216_Promote.gif

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      S 1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        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) {
        ...
        }

        S 1 Reply Last reply
        3
        • KillerSmathK KillerSmath

          @Sailanarmo
          You can promote your class directly on Qt Designer.
          0_1556744473216_Promote.gif

          S Offline
          S Offline
          Sailanarmo
          wrote on last edited by
          #4

          @KillerSmath This is exactly what I did. However it still isn't showing up when I run the program.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Do you call base class in your constructor ?

            1 Reply Last reply
            1
            • mrjjM mrjj

              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) {
              ...
              }

              S Offline
              S Offline
              Sailanarmo
              wrote on last edited by
              #6

              @mrjj This was it! Thank you, this was driving me absolutely nuts haha.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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 ?

                S 1 Reply Last reply
                0
                • mrjjM mrjj

                  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 ?

                  S Offline
                  S Offline
                  Sailanarmo
                  wrote on last edited by
                  #8

                  @mrjj I did notice that and I have changed it as well!

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved