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. Not able to show ClockLabel object
Forum Updated to NodeBB v4.3 + New Features

Not able to show ClockLabel object

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 992 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
    houmingc
    wrote on last edited by
    #1

    using ClockLabel class in http://www.java2s.com/Code/Cpp/Qt/Clocklabel.htm
    Not able to show ClockLabel although there is no error, below is my implementation.

           QLabel* label_clock;= new QLabel;
           label_clock->setFont(f);
           label_clock->setStyleSheet("QLabel { color : white; }");
    
            leftLayout = new QVBoxLayout();
            leftLayout->addWidget(label_clock);
            leftLayout->addWidget(labelOneGif);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you set that layout anywhere ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on last edited by houmingc
        #3

        Yes, i did.
        The problem seems class derives from QLabel is not able to be display by layout->addWidget. why is it so?

        window->setLayout(mainLayout);
        window->showMaximized();
        

        The class is below :
        #include <QTimer>
        #include <QTime>
        #include "clocklabel.h"

        ClockLabel::ClockLabel( QWidget *parent ) : QLabel( parent )
        {
        QTimer *timer = new QTimer( this );
        timer->setInterval( 1000 );
        connect( timer, SIGNAL(timeout()), this, SLOT(updateTime()) );
        timer->start();
        updateTime();
        }

        void ClockLabel::updateTime()
        {
        setText( QTime::currentTime().toString( "hh:mm" ) );
        }

        #ifndef CLOCKLABEL_H
        #define CLOCKLABEL_H
        #include <QLabel>

        class ClockLabel : public QLabel
        {
        Q_OBJECT
        public:
        ClockLabel( QWidget *parent = 0 );

        private slots:
        void updateTime();
        };

        #endif // CLOCKLABEL_H
        #include <QApplication>
        #include "clocklabel.h"

        int main( int argc, char **argv )
        {
        QApplication app( argc, argv );

        ClockLabel clock;
        clock.show();

        return app.exec();
        }

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          From your first example, you are not instantiating a ClockLabel but just a QLabel

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            houmingc
            wrote on last edited by
            #5

            Resolved thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What was the problem ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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