Pyqt5 help!!
-
-
Hi I have a program that should add about 40 labels(one at a time) when a button is clicked. Now I don't want to be an idiot and make blank labels and then change the text if those. Is there a more efficient way of displaying the labels. Thank you.
@Dexter99 You can create widgets (like labels) dynamically and show them:
void MainWindow::on_button_clicked() { QLabel *label = new QLabel(this, "Some text"); // Put your label into layout or position it manually label->show(); } -
@Dexter99 You can create widgets (like labels) dynamically and show them:
void MainWindow::on_button_clicked() { QLabel *label = new QLabel(this, "Some text"); // Put your label into layout or position it manually label->show(); } -
@jsulm
Not that it matters, but for the record do you have toshow()it after adding? I could swear I add dynamic labels all the time without callingshow()... -
@jsulm
Not that it matters, but for the record do you have toshow()it after adding? I could swear I add dynamic labels all the time without callingshow()...@JonB said in Pyqt5 help!!:
@jsulm
Not that it matters, but for the record do you have toshow()it after adding? I could swear I add dynamic labels all the time without callingshow()...If not added to a layout applied on a visible widget, then yes you have to call show.
-
@JonB said in Pyqt5 help!!:
@jsulm
Not that it matters, but for the record do you have toshow()it after adding? I could swear I add dynamic labels all the time without callingshow()...If not added to a layout applied on a visible widget, then yes you have to call show.
@SGaist
Ah, yes, I do mean adding to already visible widget parent/layout, so that's why I don't need to.So, I'm not criticising @jsulm's code, but where he has added
new QLabel(this, "Some text");thethisis theQMainWindow, which will be shown, so he didn't need to put in thelabel->show();, right?