Results 1 to 7 of 7

Thread: Widget Focus

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Widget Focus

    Hi,
    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

    Qt Code:
    1. for(int iter = 0; iter < count; iter++)
    2. {
    3. option1.initFrom(m_List->at(iter));
    4.  
    5. m_List->at(iter)->show();
    6. style()->drawPrimitive(QStyle::PE_Widget, &option1, &p, this);
    7. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by jpn; 13th September 2008 at 14:06. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget Focus

    Can't those widgets draw themselves?

  3. #3
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget Focus

    No I cannot. if i draw next custom widget , then previous custom widget ll disappear.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget Focus

    Quote Originally Posted by navi1084 View Post
    No I cannot.
    Why? Every normal widget is supposed to draw itself. How do you add those widgets to the parent?

  5. #5
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget Focus

    I can draw without Style option. But Widget still doesnt get the focus. Is there any way to get the focus???
    Last edited by navi1084; 29th September 2008 at 07:52.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget Focus

    drawing focus:
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *event)
    2. {
    3. ....
    4. if (hasFocus()) {
    5. QPainter painter(this);
    6. painter.save();
    7. option.initFrom(this);
    8. style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
    9. painter.restore();
    10. }
    11. ....
    12. }
    To copy to clipboard, switch view to plain text mode 
    jacek is right, all widgets have to draw own content by itself.

  7. #7
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget Focus

    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)

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 08:06
  2. widget focus ---------
    By jrodway in forum Qt Programming
    Replies: 11
    Last Post: 27th April 2009, 10:16
  3. Customize on focus widget
    By vql in forum Qt Programming
    Replies: 9
    Last Post: 9th April 2008, 19:58
  4. Managing widget focus behaviour
    By mnemonic_fx in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2008, 11:27
  5. Force focus to a QTabWidget page's widget
    By thomaspu in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2008, 07:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.