Important: Please read the Qt Code of Conduct -

Adding a label to the top/curent dialog

  • Hi All
    I want to add a label to a current dialog on top of a frame. What I do to draw the label is the following 0 ) 0 ).lable->move( 100, 100 ); 0 ) 0 ).lable->show( );

    however this opens a new widget for the label. How can I force it to draw the lable to the current dialog and the frame , eg ui->frame.
    I've tried

        ui->frame-> 0 ) 0 ).lable->move( 100, 100 );
        ui->frame-> 0 ) 0 ).lable->show( );

    but this as you'd expect gives an error. So I do I associate the label with the current dialog and the frame?


  • should add I've seen addwidget eg ui->frame->addWidget however this function doesn't seem to exist? If I use ui->frame I'm only offered addaction(s)

  • @tony67

    If your frame has a layout, you can add the widget to the layout.

    QLabel *myLabel = new QLabel(this);

  • @the_ said:

    QLabel *myLabel = new QLabel(this);

    Hi tried this and it just causes a seg fault?

  • Qt Champions 2017

    @tony67 said:

    Hi tried this and it just causes a seg fault?

    Then your frame doesn't have a layout. Then ui->frame->layout() returns NULL, and voila you get a null dereferencing thus a segfault. Add a layout to your frame, and then add the widget(s) to it. This also have the nice side effect of you not calling, move and show and any such things.

  • got it to work in a different way

        QGridLayout *layout = new QGridLayout();
        ui->frame->setLayout( layout );
    layout->addWidget( level ) element ).lable ,level ,element );

Log in to reply