c++ - Get real margins of image label in Qt -
c++ - Get real margins of image label in Qt -
my application has custom qss, , have qlabel image. image has big margins, however, come style.
this how label looks, qpixmap solid reddish show actual contents, white parts margins:
the margins 11 pixels top , bottom, 7 pixels left part, , 45 pixels right. measured them image editor, , counted border part of margins.
i tried these functions:
qdebug() << label->contentsmargins() << label->margin();
but output qmargins(0, 0, 0, 0) 0
, though there (big) margins. how calculate real/actual margins of image label?
finally managed real margins after looking qlabel::paintevent() source code. way:
qrect cr = label->contentsrect(); cr.adjust(label->margin(), label->margin(), -label->margin(), -label->margin());
edit:
in specific case seems label getting padding parent's style sheet, label->contentsmargins()
returning zeroes because calling before showing.
that is, code:
qdebug() << label->contentsmargins() << label->margin() << label->contentsrect(); label->show(); qdebug() << label->contentsmargins() << label->margin() << label->contentsrect();
produces output:
qmargins(0, 0, 0, 0) 0 qrect(0,0 62x31) qmargins(7, 1, 7, 1) 0 qrect(7,1 36x31)
c++ qt qlabel
Comments
Post a Comment