Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. why my dynamic label text get overlap ? what i need to do avoid this?

why my dynamic label text get overlap ? what i need to do avoid this?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 947 Views 1 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    #include "widget.h"
    #include "ui_widget.h"
    #include <QLabel>
    #include <qdatetime.h>
    #include <qtimer.h>
    #include <qthread.h>
    #define TIMEOUT 300

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);

    QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
    
    mtime=   QDateTime::currentMSecsSinceEpoch();
    

    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::shutdownlabel()
    {

    qint64 Newtime  = QDateTime::currentMSecsSinceEpoch() - mtime;
    //PRINT_INFO<<"newtime: " << Newtime/1000;
    Timeremain =  TIMEOUT - (Newtime/1000);
    
    QLabel *label = new QLabel(ui->frame_2);
    label->setStyleSheet("border:1px solid black;text-align:cetre;");
    label->setGeometry(50,1,202,20);
    label->clear();
    label->setText("Timer:" +QString::number(Timeremain));
    label->show();
    
    QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
    

    }

    Q 1 Reply Last reply
    0
    • Q Qt embedded developer

      #include "widget.h"
      #include "ui_widget.h"
      #include <QLabel>
      #include <qdatetime.h>
      #include <qtimer.h>
      #include <qthread.h>
      #define TIMEOUT 300

      Widget::Widget(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::Widget)
      {
      ui->setupUi(this);

      QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
      
      mtime=   QDateTime::currentMSecsSinceEpoch();
      

      }

      Widget::~Widget()
      {
      delete ui;
      }

      void Widget::shutdownlabel()
      {

      qint64 Newtime  = QDateTime::currentMSecsSinceEpoch() - mtime;
      //PRINT_INFO<<"newtime: " << Newtime/1000;
      Timeremain =  TIMEOUT - (Newtime/1000);
      
      QLabel *label = new QLabel(ui->frame_2);
      label->setStyleSheet("border:1px solid black;text-align:cetre;");
      label->setGeometry(50,1,202,20);
      label->clear();
      label->setText("Timer:" +QString::number(Timeremain));
      label->show();
      
      QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
      

      }

      Q Offline
      Q Offline
      Qt embedded developer
      wrote on last edited by Qt embedded developer
      #3

      @Qt-embedded-developer

      when i use this dynamic label in slot its slot create n label at same place and so its get overlapped to avoid this i need to take dynamic label as global and clear it every time

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        Use layouts (subclasses of QLayout) instead of manual positioning (setGeometry()).

        (Z(:^

        Q 1 Reply Last reply
        1
        • Q Qt embedded developer

          #include "widget.h"
          #include "ui_widget.h"
          #include <QLabel>
          #include <qdatetime.h>
          #include <qtimer.h>
          #include <qthread.h>
          #define TIMEOUT 300

          Widget::Widget(QWidget *parent) :
          QWidget(parent),
          ui(new Ui::Widget)
          {
          ui->setupUi(this);

          QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
          
          mtime=   QDateTime::currentMSecsSinceEpoch();
          

          }

          Widget::~Widget()
          {
          delete ui;
          }

          void Widget::shutdownlabel()
          {

          qint64 Newtime  = QDateTime::currentMSecsSinceEpoch() - mtime;
          //PRINT_INFO<<"newtime: " << Newtime/1000;
          Timeremain =  TIMEOUT - (Newtime/1000);
          
          QLabel *label = new QLabel(ui->frame_2);
          label->setStyleSheet("border:1px solid black;text-align:cetre;");
          label->setGeometry(50,1,202,20);
          label->clear();
          label->setText("Timer:" +QString::number(Timeremain));
          label->show();
          
          QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
          

          }

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by Qt embedded developer
          #3

          @Qt-embedded-developer

          when i use this dynamic label in slot its slot create n label at same place and so its get overlapped to avoid this i need to take dynamic label as global and clear it every time

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #4

            That sounds like a very wasteful approach... If you need a label there, just insert it upfront. If it does not need to be visible - hide it. If it needs to be visible - show it. If it's text needs to be changed, call setText() in your slot.

            There is no need to keep adding/ deleting labels, or clearing a global one etc.

            (Z(:^

            1 Reply Last reply
            3
            • sierdzioS sierdzio

              Use layouts (subclasses of QLayout) instead of manual positioning (setGeometry()).

              Q Offline
              Q Offline
              Qt embedded developer
              wrote on last edited by
              #5
              This post is deleted!
              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