View Full Version : Widget Focus

8th September 2008, 13:49
I have created a custom widget which will be drawn in parent widget. There can be number of custom widget drawn in parent widget(using mouse). To draw all the custom widget in parent widget, I am using following code

for(int iter = 0; iter < count; iter++)
QStyleOptionFocusRect option1;

style()->drawPrimitive(QStyle::PE_Widget, &option1, &p, this);

here m_List is QList contains all the custom Widget.
But i am facing a problem with focus. if I draw 5 custom widget , only lat drawn widget will be active. I cannot do nothing on other 4 custom widget.

Can any one tell me how can i resolve this issue.???

Thank You

9th September 2008, 00:59
Can't those widgets draw themselves?

9th September 2008, 05:54
No I cannot. if i draw next custom widget , then previous custom widget ll disappear.

12th September 2008, 23:32
No I cannot.
Why? Every normal widget is supposed to draw itself. How do you add those widgets to the parent?

29th September 2008, 06:14
I can draw without Style option. But Widget still doesnt get the focus. Is there any way to get the focus???

29th September 2008, 08:54
drawing focus:

void MyWidget::paintEvent(QPaintEvent *event)
if (hasFocus()) {
QPainter painter(this);
QStyleOptionFocusRect option;
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);

jacek is right, all widgets have to draw own content by itself.

29th September 2008, 11:22
Thank you for the reply.

I have came across my problem. Actually my widget is meant for rectangles. i.e in parent widget we can draw transparent rectangle widgets which is rectangle in shape of certain colors. when i draw first rect then all the parent widget area is occupied by this and get the focus. When i draw one more rect widget then this rect get focus and previous rect loses its focus. since the rect widgets are transparent all the rect widget can be showned.
I have handled mouseEvent to rect widgets. But when i add a new rect widget mouseEvent comes only for this widget. Other rect widgets will loses its focus(mouseEvents).
So is there any way to make all the widget gets mouseEvent.
(Actually curser should change when the mouse hovers to perticular rect widget)