[Solved]How to calculate the border-width of a widget in the paintEvent?
I have a custom widget for which i have specified the stylesheet as
@setStyleSheet("border: 5px solid red");@
which can also be specified in a qss file like
border: 10px solid red;
Since its a QWidget so to make the styleSheet work i added in the paintEvent() fuction of MyWidget
@void MyWidget::paintEvent(QPaintEvent *e)
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
The above code has the following output
How can I calculate/get the border-width in the paintEvent() if the border is specified using stylesheet;
After working on this for few hrs i figured out that QWidget does not provide any information about the border-width. So instead of using QWidget i use QFrame.
My requirement was to paint in the available area excluding the border for a widget.
This is achieved by using QFrame that provide "frameWidth()":http://doc.qt.nokia.com/4.7-snapshot/qframe.html#frameWidth-prop and "contentsRect()":http:// for the same purpose.