Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display qLabel child on top of QPushButton not working.
Forum Updated to NodeBB v4.3 + New Features

Display qLabel child on top of QPushButton not working.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 705 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EneClaudiu
    wrote on last edited by
    #1

    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);
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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);

      1 Reply Last reply
      2
      • E Offline
        E Offline
        EneClaudiu
        wrote on last edited by
        #3

        Thak you!
        Never would have guessed that the position changes when you re-parent it.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved