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
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
Last edited by jakr13; 5th December 2014 at 06:05.
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,
_
@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
Last edited by jakr13; 5th December 2014 at 08:22.
So what exactly is the problem? You don't know how to create a label?
Qt Code:
To copy to clipboard, switch view to plain text mode
@wysota I am familiar with creating labels, but I dont know how to create dynamic labels.
gui.jpg 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;
Last edited by jakr13; 5th December 2014 at 13:24.
To create labels at runtime use the "new" operator like I showed in post #4.
jakr13 (6th December 2014)
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
Bookmarks