Get margins of QPushButton
-
@goldstar2154 said in Get margins of QPushButton:
Shoud i open bug?
Either open a bug or write to the dev mailing list as i wrote.Have developers read this forum?
no this forum isn't read by the developers. The dev mailing list is.
-
@zhangsi said in Get margins of QPushButton:
you can call QPushButton::styleSheet function to get margin from string, why not
if it just would be that easy...
-
@goldstar2154 , @raven-worx Have you found how to solve this problem with qpushbutton margins in paintevent?
-
@CppHamster
you can try the QStyle way:void QDelayPushButton::paintEvent(QPaintEvent* event) { QPushButton::paintEvent(event); QStyleOptionButton option; this->initStyleOption(&option); QRect contentsRect = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this ); ... }
-
@raven-worx Thank you! But still does not work
-
@raven-worx finally, i've got the contents size by using your advice:
1: QRect contentsRect1 = this->style()->subElementRect( QStyle::SE_PushButtonLayoutItem, &option, this );
2: QRect contentsRect2 = this->style()->subElementRect( QStyle::SE_PushButtonContents, &option, this );
3: QRect contentsRect3 = this->style()->subElementRect( QStyle::SE_PushButtonFocusRect, &option, this );qDebug() with QPushbutton properties:
width: 134
height: 45
.....
QMargins(0, 0, 0, 0) // <- QMargins margins = this->contentsMargins();
.....
1: QRect(0,0 0x0)
2: QRect(1,1 132x43)
3: QRect(1,1 132x43)The difference is border width.
-
@goldstar2154 if the code is correct, you can mark this question as "solved"
-
@CppHamster this code is correct technically, but not logically. If we have contentsMargins() method it shoud work...
P.S. i've marked question as solved, but still think is a bug
P.P.S. and thanks for solution, of course) -
@goldstar2154 Totally agree with you - there is a obvious bug. But thanks to @raven-worx 's code we've got a way to get a result at least. And "solved" will help in web search:)
Thank you very much for this question:)