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. QLabel inside another QLabel (code provided)

QLabel inside another QLabel (code provided)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.1k Views 1 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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by VRonin
    #1

    I have a label which I have create using the UI creatot(dragged the label on mainwindow) and now I want to create a label inside the label, and inside the label which has been created with code I want to display a message to indicate that everything is ok. How I can do this? I have overloaded the paintEvent so I could draw the borders of the labels(to see them).

    void MainWindow::paintEvent(QPaintEvent *event){
    
     if(divide == 2){
     P1.begin(this);
     P1.setPen(Qt::PenStyle::DashLine);
     P1.drawRect(ui->mainlabel->x(),ui->mainlabel>y()*2,ui->mainlabel->width()/2,ui->mainlabel->height()/2);
     P1.end();
    
     S2_0 = new QLabel(ui->mainlabel);
     S2_0->setFrameStyle(QFrame::Panel | QFrame::Sunken);
     S2_0->setGeometry(ui->mainlabel->x(),ui->mainlabel>y()*2,ui->mainlabel->width()/2,ui->mainlabel->height()/2);
     S2_0->setText("hello""); S2_0->setAlignment(Qt::AlignCenter);
    
    }
    

    When divide is changed i call repaint();

    Mandruk1331

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      could you show us an image with what you want as final result?

      i suspect what you are really after is a widget with layout with 2 labels in it

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      mandruk1331M 1 Reply Last reply
      3
      • VRoninV VRonin

        could you show us an image with what you want as final result?

        i suspect what you are really after is a widget with layout with 2 labels in it

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by
        #3

        @VRonin yes that's what I want. I have found that I have to create a layout and then store the label inside the layout, but at the moment I don't have a clue how to do it.

        Mandruk1331

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          http://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            Here's a quick example:

            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(new Label("my first label");
            layout->addWidget(new Label("my second label");
            
            setLayout(layout);
            

            That would make a vertical box with label 1 on top of label 2. You can control sizing and spacing with the layout.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            1

            • Login

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