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. Adding a label to the top/curent dialog
QtWS25 Last Chance

Adding a label to the top/curent dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.1k Views
  • 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.
  • T Offline
    T Offline
    tony67
    wrote on last edited by A Former User
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tony67
      wrote on last edited by
      #2

      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)

      the_T 1 Reply Last reply
      0
      • T tony67

        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)

        the_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #3

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

        -- No support in PM --

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tony67
          wrote on last edited by
          #4

          @the_ said:

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

          Hi tried this and it just causes a seg fault?

          kshegunovK 1 Reply Last reply
          0
          • T tony67

            @the_ said:

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

            Hi tried this and it just causes a seg fault?

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @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.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tony67
              wrote on last edited by
              #6

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