Nominate our 2022 Qt Champions!

Custom widget border-radius stylesheet

  • Well, suppose I have a custom widget with my custom paint event
    class customWidget : public QWidget
    // constructor etc.
    void paintEvent(QPaintEvent *e) { // some painting here };

    Then I add this widget to the layout and set it's stylesheet. Like that
    // in main window constructor
    customWidget *custom=new customWidget;
    custom->setStyleSheet("border-top-right-raduis: 8px;");

    So, how to account for border-top-right-radius in paint event of my widget? Or how to know of those 8px raduis inside paint event.

  • Hi elephanten

    I'm not quiet sure what you are trying to do?
    It seams to me that you are mixing the stylesheet approach with the inherit by QStyle approach.

    Why would you need stylesheet in your customwidget where you have full control of paintEvent?

    Also good is to checkout the source of QWidget

    or here

    or here

    or the examples of qt

  • Ah, ok.
    My custom widget is placed inside qscrollarea, which in turn has a stylesheet, specifying border-raduis. My widget is then rendered over the border-radius, which is ugly. Is it true, that I, oh-ah, just have do like that:
    class customWidget : public QAbstractSrollArea
    // all the mess with painting


Log in to reply