[vtkusers] QVTKWidget border radius

somi seesomi at gmail.com
Tue Aug 21 23:21:47 EDT 2012


Sorry for the spam. I think I found my answer.

just in case if anyone has a similar problem, this is how I solved it.

Turns out QWidget doesn't support border-radius stylesheet property.
So I had to set a mask:


void setWidgetBorderRadius(QWidget* widget, int radius) {

    // cache widget with and height
    int width = widget->width();
    int height = widget->height();

    // Initialize a rectangular masked region
    QRegion region(0, 0, width, height, QRegion::Rectangle);

    // now clip off the sharp edges

    // top left
    QRegion round (0, 0, 2*radius, 2*radius, QRegion::Ellipse);
    QRegion corner(0, 0, radius, radius, QRegion::Rectangle);
    region = region.subtracted(corner.subtracted(round));

    // top right
    round = QRegion(width-2*radius, 0, 2*radius, 2*radius,
QRegion::Ellipse);
    corner = QRegion(width-radius, 0, radius, radius, QRegion::Rectangle);
    region = region.subtracted(corner.subtracted(round));

    // bottom right
    round = QRegion(width-2*radius, height-2*radius, 2*radius, 2*radius,
QRegion::Ellipse);
    corner = QRegion(width-radius, height-radius, radius, radius,
QRegion::Rectangle);
    region = region.subtracted(corner.subtracted(round));

    // bottom left
    round = QRegion(0, height-2*radius, 2*radius, 2*radius,
QRegion::Ellipse);
    corner = QRegion(0, height-radius, radius, radius, QRegion::Rectangle);
    region = region.subtracted(corner.subtracted(round));

    // Set mask
    widget->setMask(region);
}

References:
http://qt-project.org/doc/qt-5.0/stylesheet-reference.html
http://www.qtcentre.org/threads/44316-Rounded-corners-for-a-QWidget?s=fd88b7c4e59f4487a5457db551f3df2c


On Tue, Aug 21, 2012 at 10:22 PM, somi <seesomi at gmail.com> wrote:

> Hi,
> I am trying to use a QVTKWidget in a QT  UI file. In QTcreator, I am able
> to set the border radius
> to some value via stylesheets to get a rounded borders. In QTCreator I can
> see the rounded
> borders. However on running the program QVTKWidget ignores the border
> radius and renders as a rectangle.
>
> Am I missing something trivial ? what would be the best way for QVTKWidget
> to render
> rounded corners ?
>
> Thanks,
> somi
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120821/1fd73a00/attachment.htm>


More information about the vtkusers mailing list