PDA

View Full Version : How to get Rect or Size by QStyle?



nifei
18th November 2008, 09:59
Hi, all.
I subclass QTableView and reimplement

QTableView::mouseReleaseEvent(QEvent *event)
, in which i get

QTableView::currentIndex()
and the event pos by

event->pos()
before this i've set some items checkable so there is a checkbox in the responding positions.
Now, i'm wondering how can i get the checkbox's geometry, rect or size? which is devided from the item's other part. as in the attachment, i want to know the red rectangle's rect or just size.

By now i can get the whole item's rect through it's index and the style of this view. by the way, the view's indicator's appearence is set by a stylesheet.

thank you.

aamer4yu
18th November 2008, 19:38
What do you want to know the size for ?

That size is basically passed by tableview to delegate. are u using delegates ?

nifei
19th November 2008, 01:58
What do you want to know the size for ?

That size is basically passed by tableview to delegate. are u using delegates ?

I want to know the size of the checkBox in the tableView's item, that is the rectangle displaying a checkBox, when the item is set user checkable, we could do this by calling
QStandardItem::setCheckable(bool).

I haven't used custom delegate.

aamer4yu
19th November 2008, 04:11
So what are u gonna do even if u get the rectangle of the checkbox ??

or does QStandardItem::setCheckable(bool) solve ur prob ?

nifei
19th November 2008, 08:54
So what are u gonna do even if u get the rectangle of the checkbox ??

or does QStandardItem::setCheckable(bool) solve ur prob ?


QStandardItem::setCheckable(bool) can put a check box in the view's item. i can check or uncheck the checkbox by clicking it, however, i want to check or uncheck the checkbox by clicking any position of the item, including the checkbox. so I reimplement
QTableView::mouseReleaseEvent(QEvent *event), and have to judge whether the mouse event position is inside or outside the check box,

in one word: i need different operations when mouse event happens inside and outside the checkbox, so i have to know the checkbox's rect.

aamer4yu
19th November 2008, 09:03
i want to check or uncheck the checkbox by clicking any position of the item, including the checkbox. so I reimplement
QTableView::mouseReleaseEvent(QEvent *event)
, and have to judge whether the mouse event position is inside or outside the check box,

I dont think u need to manipulate check box area... u just need to toggle check state on mouse release event fo that index... hope am getting u rright

nifei
21st November 2008, 03:45
I dont think u need to manipulate check box area... u just need to toggle check state on mouse release event fo that index... hope am getting u rright

Yes, I implement
MouseReleaseEvent(QMouseEvent *) and when clicking the area of that index , besides the check box area, it works well. but when clicking the checkbox, the check box is toggled, and the mouseReleaseEvent also works, so it equals to set the check state twice! and the check box is toggled and toggled again. so i need to prevent setting the check state myself of that index when the
event->pos() is inside the check box.

Thank you for answering my questions!

aamer4yu
21st November 2008, 04:20
Usually icons have a size of 16x16. So u can assume checkbox to be 16 or 18 pixels wide and try ur code..
error of 1-2 pixels wont affect much... user wont gonna hit exactly where u ain't trapping mouse press :)

nifei
21st November 2008, 09:09
Usually icons have a size of 16x16. So u can assume checkbox to be 16 or 18 pixels wide and try ur code..
error of 1-2 pixels wont affect much... user wont gonna hit exactly where u ain't trapping mouse press :)

your advice is useful when the default style is used. however, i want to control the style of check box by Style Sheet, that is to say, the size of a check box may be different to default one. thank you.