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. Put a QLabel on anothers QLabels
Forum Updated to NodeBB v4.3 + New Features

Put a QLabel on anothers QLabels

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 420 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!!

    I am trying to do something more visual that I have. I want to put a QLabel on anothers QLabels like this picture:

    0_1517213203471_0c3f24ad-14bc-4842-90b3-504c6554e4a9-imagen.png

    Each color is a QLabel and I want to put text on this labels.

    How coul I do it?

    Thank you very much!!!

    raven-worxR 1 Reply Last reply
    0
    • ivanicyI ivanicy

      Hello!!

      I am trying to do something more visual that I have. I want to put a QLabel on anothers QLabels like this picture:

      0_1517213203471_0c3f24ad-14bc-4842-90b3-504c6554e4a9-imagen.png

      Each color is a QLabel and I want to put text on this labels.

      How coul I do it?

      Thank you very much!!!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @ivanicy
      does it really have to be a composition of labels?

      Depending on your requirements it would be easier (at least less code) if you just do the painting (on a custom QFrame widget):

      void MyFrame::paintEvent( QPaintEvnet* event )
      {
          QFrame::paintEvent( event );
      
          QPainter p(this);
             p.setRenderHints( QPainter::TextAntialiasing | QPainter::Antialiasing );
      
         const int sectionWidth = this->contentsRect().width() / 7;
         const int sectionHeight = this->contentsRect().height();
      
         // draw color rects
         p.setBrush( Qt::yellow );
         p.drawRect( 0 * sectionWidth , 0 , sectionWidth, sectionHeight );
      
         p.setBrush( Qt::blue );
         p.drawRect( 1 * sectionWidth , 0 , sectionWidth, sectionHeight );
      
         p.setBrush( Qt::green );
         p.drawRect( 2 * sectionWidth , 0 , sectionWidth, sectionHeight );
         .....
      
         // draw text
         p.setFont( ... );
         p.setPen( Qt::white );
         p.drawText( this->contentsRect(), Qt::AlignCenter, "LabelText" );
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      5

      • Login

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