How to create labels dynamically according to the slider value
Hello everyone,
How can I create QLabel dynamically depending on the slider input? eg. if slider value is 3, then I need to create 3 labels. any suggestions or examples will be really appreciated.
Thanks in advance!!!
jakr13
Re: How to create labels dynamically according to the slider value
The control structure for that in C++ is called a loop, in this case a good candidate would be a for loop.
Any C++ tutorial on the net will likely have a section on loops.
Cheers,
_
Re: How to create labels dynamically according to the slider value
@anda_skoa I didn't mean about loops
int no_of labels = ui->slider->value();
for(int i=1; i<=no_of_labels; i++)
{
// what I have to do here??
}
Suppose if no_of_labels is 5, i have to create 5 labels dynamically label1, label2, label3, label4 & label5 and display images in each label. how to do this?
I have created 8 labels statically and displaying the images according to the no_of_labels. Suppose if the no_of_label is 5, 5 labels are shown with corresponding images, the remaining three labels are left free. I dont want that. so I decided to create labels dynamically depending on the slider value.
Jakr13
Re: How to create labels dynamically according to the slider value
So what exactly is the problem? You don't know how to create a label?
Re: How to create labels dynamically according to the slider value
@wysota I am familiar with creating labels, but I dont know how to create dynamic labels.
Re: How to create labels dynamically according to the slider value
What are "dynamic labels"?
1 Attachment(s)
Re: How to create labels dynamically according to the slider value
Attachment 10783 I have static labels as show in attached image. I dont want to have static labels and I am trying to create labels at runtime. The no of labels depends on the slider value;
Re: How to create labels dynamically according to the slider value
To create labels at runtime use the "new" operator like I showed in post #4.
Re: How to create labels dynamically according to the slider value
I was thinking of so much that I have to do to create labels at run time. I was so stupid, because it was so simple. Got it worked, thanks @Wysota and @anda_skoa