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. Progress bar with text
Forum Updated to NodeBB v4.3 + New Features

Progress bar with text

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.1k Views 5 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    Is there a way to have a progress bar that has text overlaid on it like this:

    Progress bar with text.png

    Thanks
    David

    Chris KawaC 1 Reply Last reply
    0
    • PerdrixP Perdrix

      @Chris-Kawa I'm "guessing" that Designer won't let me add a QLabel that is a child of the progress bar.

      The ui file generates setupUi code like this:

              verticalLayout = new QVBoxLayout();
              verticalLayout->setObjectName("verticalLayout");
              verticalSpacer_1 = new QSpacerItem(20, 13, QSizePolicy::Minimum, QSizePolicy::Fixed);
      
              verticalLayout->addItem(verticalSpacer_1);
      
              progressBar = new QProgressBar(widget_2);
              progressBar->setObjectName("progressBar");
              progressBar->setValue(24);
      
              verticalLayout->addWidget(progressBar);
      
              status = new QLabel(widget_2);
              status->setObjectName("status");
              QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
              sizePolicy1.setHorizontalStretch(0);
              sizePolicy1.setVerticalStretch(0);
              sizePolicy1.setHeightForWidth(status->sizePolicy().hasHeightForWidth());
              status->setSizePolicy(sizePolicy1);
      
              verticalLayout->addWidget(status);
      

      Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar, with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #4

      @Perdrix said:

      Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar

      Yes

      with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

      You could, but that's what layouts are for and labels have transparent backgrounds by default.

      auto label = new QLabel("Hello!");
      label->setAlignment(Qt::AlignCenter);
      
      auto layout = new QVBoxLayout(ui->progressBar);
      layout->setContentsMargins(0,0,0,0);
      layout->addWidget(label);
      
      PerdrixP 1 Reply Last reply
      6
      • PerdrixP Perdrix

        Is there a way to have a progress bar that has text overlaid on it like this:

        Progress bar with text.png

        Thanks
        David

        Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Perdrix The simplest would be to add a QLabel as a child of the progress bar.

        PerdrixP 1 Reply Last reply
        0
        • Chris KawaC Chris Kawa

          @Perdrix The simplest would be to add a QLabel as a child of the progress bar.

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #3

          @Chris-Kawa I'm "guessing" that Designer won't let me add a QLabel that is a child of the progress bar.

          The ui file generates setupUi code like this:

                  verticalLayout = new QVBoxLayout();
                  verticalLayout->setObjectName("verticalLayout");
                  verticalSpacer_1 = new QSpacerItem(20, 13, QSizePolicy::Minimum, QSizePolicy::Fixed);
          
                  verticalLayout->addItem(verticalSpacer_1);
          
                  progressBar = new QProgressBar(widget_2);
                  progressBar->setObjectName("progressBar");
                  progressBar->setValue(24);
          
                  verticalLayout->addWidget(progressBar);
          
                  status = new QLabel(widget_2);
                  status->setObjectName("status");
                  QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
                  sizePolicy1.setHorizontalStretch(0);
                  sizePolicy1.setVerticalStretch(0);
                  sizePolicy1.setHeightForWidth(status->sizePolicy().hasHeightForWidth());
                  status->setSizePolicy(sizePolicy1);
          
                  verticalLayout->addWidget(status);
          

          Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar, with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

          Chris KawaC 1 Reply Last reply
          1
          • PerdrixP Perdrix

            @Chris-Kawa I'm "guessing" that Designer won't let me add a QLabel that is a child of the progress bar.

            The ui file generates setupUi code like this:

                    verticalLayout = new QVBoxLayout();
                    verticalLayout->setObjectName("verticalLayout");
                    verticalSpacer_1 = new QSpacerItem(20, 13, QSizePolicy::Minimum, QSizePolicy::Fixed);
            
                    verticalLayout->addItem(verticalSpacer_1);
            
                    progressBar = new QProgressBar(widget_2);
                    progressBar->setObjectName("progressBar");
                    progressBar->setValue(24);
            
                    verticalLayout->addWidget(progressBar);
            
                    status = new QLabel(widget_2);
                    status->setObjectName("status");
                    QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Preferred);
                    sizePolicy1.setHorizontalStretch(0);
                    sizePolicy1.setVerticalStretch(0);
                    sizePolicy1.setHeightForWidth(status->sizePolicy().hasHeightForWidth());
                    status->setSizePolicy(sizePolicy1);
            
                    verticalLayout->addWidget(status);
            

            Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar, with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #4

            @Perdrix said:

            Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar

            Yes

            with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

            You could, but that's what layouts are for and labels have transparent backgrounds by default.

            auto label = new QLabel("Hello!");
            label->setAlignment(Qt::AlignCenter);
            
            auto layout = new QVBoxLayout(ui->progressBar);
            layout->setContentsMargins(0,0,0,0);
            layout->addWidget(label);
            
            PerdrixP 1 Reply Last reply
            6
            • Chris KawaC Chris Kawa

              @Perdrix said:

              Am I right in thinking that I will need to add the QLabel after setupUi has run making it a child of progressBar

              Yes

              with transparent background and no frame AND that I will have to handle resize events to resize the label to match the size of the progress bar?

              You could, but that's what layouts are for and labels have transparent backgrounds by default.

              auto label = new QLabel("Hello!");
              label->setAlignment(Qt::AlignCenter);
              
              auto layout = new QVBoxLayout(ui->progressBar);
              layout->setContentsMargins(0,0,0,0);
              layout->addWidget(label);
              
              PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #5

              @Chris-Kawa Nice! I get the impression you actually done this label on top of progress bar thing before :).

              Pl45m4P 1 Reply Last reply
              1
              • PerdrixP Perdrix has marked this topic as solved on
              • PerdrixP Perdrix

                @Chris-Kawa Nice! I get the impression you actually done this label on top of progress bar thing before :).

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #6

                @Perdrix

                Parent-Child mechanism :)
                You can put any widget on top of any other widget (in its coordinate system) by setting the bottom widget as parent of the toplevel one.
                In this case @Chris-Kawa used a layout


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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