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. new class inherited from QLabel not showing in parent window

new class inherited from QLabel not showing in parent window

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 301 Views 2 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.
  • H Offline
    H Offline
    herrgross
    wrote on last edited by herrgross
    #1

    Hi everyone,
    I created a new class inherited from QLabel.

    #ifndef WANDERLABEL_H
    #define WANDERLABEL_H
    
    #include <QLabel>
    #include <QTimer>
    
    class wanderLabel : public QLabel
    {
        Q_OBJECT
    public:
        wanderLabel();
    private:
        QTimer* timer;
    private slots:
        void moveLabel();
    };
    
    #endif // WANDERLABEL_H
    

    in my cpp I added:

    Matrix::Matrix(QWidget *parent)
        : QMainWindow(parent)
    {
        setGeometry(400, 300, 400, 400);
        QLabel* test;
        test = new QLabel(this);
        test->setText("test");
        wanderLabel* wanderer;
        wanderer = new wanderLabel(this);
        wanderer->setText("1");
    //wanderer->show();
    }
    

    while any QLabel instance is correctly showing,
    creating an instance of wanderlabel gives me the error: no matching constructor.
    So I changed the constructor:
    wanderLabel(QWidget *parent = nullptr);
    now, after adding show() it shows, but not in the widget, but as a new widget on the main screen.
    What am I missing?

    Paul ColbyP 1 Reply Last reply
    0
    • H herrgross

      Hi everyone,
      I created a new class inherited from QLabel.

      #ifndef WANDERLABEL_H
      #define WANDERLABEL_H
      
      #include <QLabel>
      #include <QTimer>
      
      class wanderLabel : public QLabel
      {
          Q_OBJECT
      public:
          wanderLabel();
      private:
          QTimer* timer;
      private slots:
          void moveLabel();
      };
      
      #endif // WANDERLABEL_H
      

      in my cpp I added:

      Matrix::Matrix(QWidget *parent)
          : QMainWindow(parent)
      {
          setGeometry(400, 300, 400, 400);
          QLabel* test;
          test = new QLabel(this);
          test->setText("test");
          wanderLabel* wanderer;
          wanderer = new wanderLabel(this);
          wanderer->setText("1");
      //wanderer->show();
      }
      

      while any QLabel instance is correctly showing,
      creating an instance of wanderlabel gives me the error: no matching constructor.
      So I changed the constructor:
      wanderLabel(QWidget *parent = nullptr);
      now, after adding show() it shows, but not in the widget, but as a new widget on the main screen.
      What am I missing?

      Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by
      #2

      @herrgross said in new class inherited from QLabel not showing in parent window:

      So I changed the constructor:
      wanderLabel(QWidget *parent = nullptr);

      Did you pass the parent pointer to the super class? eg

      wanderLabel::wanderLabel(QWidget *parent = nullptr)
          : QLabel(parent) ///< this part?
      {
      }
      

      Cheers.

      H 1 Reply Last reply
      2
      • Paul ColbyP Paul Colby

        @herrgross said in new class inherited from QLabel not showing in parent window:

        So I changed the constructor:
        wanderLabel(QWidget *parent = nullptr);

        Did you pass the parent pointer to the super class? eg

        wanderLabel::wanderLabel(QWidget *parent = nullptr)
            : QLabel(parent) ///< this part?
        {
        }
        

        Cheers.

        H Offline
        H Offline
        herrgross
        wrote on last edited by
        #3

        @Paul-Colby
        that's what it was! thank you!!

        1 Reply Last reply
        0

        • Login

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