Put a QLabel on anothers QLabels
Unsolved
General and Desktop
-
Hello!!
I am trying to do something more visual that I have. I want to put a QLabel on anothers QLabels like this picture:
Each color is a QLabel and I want to put text on this labels.
How coul I do it?
Thank you very much!!!
@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" ); }