Results 1 to 2 of 2

Thread: border-radius doesn't clip the background using QLabel::render()

  1. #1
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded

    Default border-radius doesn't clip the background using QLabel::render()

    Hi,

    I'm having trouble using border-radius, in that it doesn't clip the background.

    I am using QLabel as a renderer onto a listview using a delegate:

    Qt Code:
    1. void MyDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const {
    2.  
    3. const QWidget *widget = opt.widget;
    4. QStyle *style = widget ? widget->style() : QApplication::style();
    5. QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt);
    6.  
    7. QLabel lbl;
    8. lbl.setObjectName("Godzilla");
    9. painter->save();
    10. painter->translate(textRect.topLeft());
    11. lbl.setText("Godzilaaaaaaaaaaaaa");
    12. lbl.render(painter);
    13. painter->restore();
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    My stylesheet is:

    Qt Code:
    1. #Godzilla {
    2. border-radius: 5px;
    3. background: rgba(255,0,0,80);
    4. border: 2px solid red;
    5. color: white;
    6. font-weight: bold;
    7. font-size: 10px;
    8. }
    To copy to clipboard, switch view to plain text mode 

    The stylesheet is loaded using qApp->setStyleSheet(..);
    The style applies (color, border, background), but, the background doesn't clip.

    I've tried using

    Qt Code:
    1. setAttribute(Qt::WA_NoSystemBackground,true);
    To copy to clipboard, switch view to plain text mode 

    but it just prevents the background and borders from drawing at all.

    I am using Qt 4.7 on Windows XP.

    TIA
    Last edited by mritalian; 13th April 2011 at 23:10.

  2. #2
    Join Date
    Apr 2011
    Posts
    2
    Qt products
    Qt4 Qt/Embedded

    Default Re: border-radius doesn't clip the background using QLabel::render()

    Found the cause!

    Qt Code:
    1. lbl.render(painter);
    To copy to clipboard, switch view to plain text mode 

    The prototype for QWidget::render is:


    Qt Code:
    1. void render(QPainter *painter, const QPoint &targetOffset = QPoint(),
    2. const QRegion &sourceRegion = QRegion(),
    3. RenderFlags renderFlags = DrawWindowBackground | DrawChildren));
    To copy to clipboard, switch view to plain text mode 

    So the fix is (obviously)

    Qt Code:
    1. lbl.render(painter, QPoint(), QRegion(), 0);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Border radius unix/windows
    By dacrawler in forum Newbie
    Replies: 2
    Last Post: 23rd January 2011, 13:27
  2. QFrame with border-radius inside QGraphicsScene
    By DeRatizator in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2010, 08:39
  3. QLabel background color doesn't work in toolbars
    By iig in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2010, 11:30
  4. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36
  5. (qt4 & xp) qlabel as background in designer
    By incapacitant in forum Newbie
    Replies: 5
    Last Post: 5th March 2006, 11:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.