Qt World Summit: Submit your Presentation

What is the alternate for StyleSheet to set the background and bottom border of a custom widget derived from the QWidget?

  • I Have a custom widget derived from QWidget

    it contain two labels. Now I want to fill the background of the Custom widget ( which include the child widget) with red and set the bottom border with 2px thickness and color dark red. I dont want to use stylesheet, since its organization policy to rely less on style sheet.

    What i tried?

    I override the paintevent and have made use of the below code to fill the rectangle

    QPainter painter(this);
    painter.fillRect(rect(), QColor(170,30,330));

    this worked for me. I am still in a doubt how to set the border width and color.

  • Lifetime Qt Champion

    You can look how QFrame does.

    void QFrame::drawFrame(QPainter *p)
        QStyleOptionFrame opt;
        style()->drawControl(QStyle::CE_ShapedFrame, &opt, p, this);

    However, it would be easier to just inherit from QFrame instead so you can just set properties and
    not values in QStyleOptionFrame.

Log in to reply