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

        game_layout.board.at( 0 ).level_data.at( 0 ).lable->move( 100, 100 );
        game_layout.board.at( 0 ).level_data.at( 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->game_layout.board.at( 0 ).level_data.at( 0 ).lable->move( 100, 100 );
        ui->frame->game_layout.board.at( 0 ).level_data.at( 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?

    Thanks



  • 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);
    ui->frame->layout()->addWidget(myLabel);
    


  • @the_ said:

    QLabel *myLabel = new QLabel(this);
    ui->frame->layout()->addWidget(myLabel);

    Hi tried this and it just causes a seg fault?


  • Qt Champions 2016

    @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(  game_layout.board.at( level ).level_data.at( element ).lable ,level ,element );
    
    
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.