PDA

View Full Version : How to get the padding or margins set in style sheet?



nifei
25th November 2008, 10:14
Hi, all.
foi set some widget's padding and margins in a style sheet. and how can i get it in my code? for example, i write:

QTableView::item{
padding:10px;
margins:10px;
border:1px solid red;
border-radius:5px;
}

and i reimplement
QStyledItemDelegate::(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)const, i want the padding and margins of this item here, what shall i do?

i wonder item's padding and margins since i want to put html-text in the item, and paint the html-text by self when implementing paint(), however, i have to translate correctly to the rect that text should be displayed, or else, the text might be overlapped with the borders.

Thank you.

aamer4yu
25th November 2008, 13:57
If you are using delegates, you get rect in const QStyleOptionViewItem &option argument.
option.rect() [QStyleOption::rect ]
Hope this helps :)

manuelschneid3r
7th March 2024, 12:40
option.rect gives you just the rect including the padding. Any solution to this?