Progress bar with text
-
@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?
@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);
-
Is there a way to have a progress bar that has text overlaid on it like this:
Thanks
David@Perdrix The simplest would be to add a QLabel as a child of the progress bar.
-
@Perdrix The simplest would be to add a QLabel as a child of the progress bar.
@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-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?
@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);
-
@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);
@Chris-Kawa Nice! I get the impression you actually done this label on top of progress bar thing before :).
-
P Perdrix has marked this topic as solved on
-
@Chris-Kawa Nice! I get the impression you actually done this label on top of progress bar thing before :).