Results 1 to 3 of 3

Thread: Set focus to other control when clicking a QPushButton

  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Set focus to other control when clicking a QPushButton

    Hi,

    I have a table (QTableView) in which a user can select a row. Then I have 2 buttons to change a field in this table to a fixed value. The first buttons sets the field to 'M', the other one to 'D'.

    When the user presses one of the buttons with the mouse, the QTableview loses focus. I want the focus to stay on the QTableView. How could I do this ?

    The reason is that I would like the user to be able to select a record using the cursor keys, press one of the buttons, and then continue to select a different record without first having to set the focus to the table.

    I tried to use setFocus() of the QTableView widget in the clicked() event of my pushbuttons, and in the release() event, but this doesn't work.

    Any suggestions ?

    Best regards,
    Marc

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Set focus to other control when clicking a QPushButton

    QWidget::focusPolicy() on the push buttons perhaps. Disable focus by click.

  3. The following user says thank you to ChrisW67 for this useful post:

    marcvanriet (12th October 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Set focus to other control when clicking a QPushButton

    set a strong focus for the view and Qt::NoFocus for the buttons (as policies).

    Edit: Ehm, what's up with me? The answer was already given by ChrisW67. Sorry, just ignore my post.

Similar Threads

  1. Replies: 3
    Last Post: 4th May 2011, 14:29
  2. How can i avoid QPushButton Focus Rectangle
    By nightroad in forum Newbie
    Replies: 8
    Last Post: 4th October 2010, 10:06
  3. Replies: 5
    Last Post: 15th June 2010, 21:32
  4. Replies: 0
    Last Post: 16th December 2009, 09:45
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.