Not able to show ClockLabel object



  • 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);

  • Lifetime Qt Champion

    Hi,

    Do you set that layout anywhere ?



  • 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();
    }


  • Lifetime Qt Champion

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



  • Resolved thanks


  • Lifetime Qt Champion

    What was the problem ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.