Display qLabel child on top of QPushButton not working.
-
I created a QPushButton using the ui window and put a QLabel on top of it for the text wrap.
The problem is that i can not get the label to display on top of the button.
I assigned the parrent like this:ui.myLabel->setParent(ui.pushButton);I am confused because if i created the label in code it would automatically be displayed on top of the parrent:
QLabel * myLabel= new QLabel(ui.pushButton); -
First check where you do that. When you add a child widget when parent is already visible child is not shown automatically. You need to call
show()expliciltly in that case.Second thing is that when you create the label in the designer it gets some position. When you re-parent it from code it retains that position but now in new parent, which might be out of bounds of the button. Make sure it is positioned on the visible portion of the button e.g.
ui.myLabel->move(0,0);.You'll probably want the label to resize itself to match the button size too, so you might as well put it in a layout:
(new QVBoxLayout(ui.pushButton))->addWidget(ui.label); -
Thak you!
Never would have guessed that the position changes when you re-parent it.