×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    May 2009
    Posts
    146

    How to get rid of focus rectangle?

    When I select for example a QPushbutton when running my app in the Symbian Emulator I get this white inner border like in this picture:



    I've heard that it is because the button gets the focus and it's the focus rectangle. Is the only way to get rid of this to alter the paint event? I'm using stylesheets when styling my app, can I in some way get rid of the rectangle using stylesheets?

    It seems like a mass of work if I need to alter the paint event for each QPushbutton, QTabbar, QListWidgetItem and so on to get rid of this rectangle?

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to get rid of focus rectangle?

    Don't accept focus: setFocusPolicy(Qt::NoFocus)

  3. #3
    Regular Contributor
    Join Date
    May 2009
    Posts
    146

    Re: How to get rid of focus rectangle?

    Thanks! That made the ugly rectangle go away but now the button wouldn't accept my stylesheet for:
    Code:
    QPushButton:selected { 
      background: red;
    }
    So I can choose between having the ugly rectangle and be able to style the button when selected OR no rectangle but also no style when selected at all? Or am I doing something wrong here?

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to get rid of focus rectangle?

    Well, the ugly rectangle is largely there for tabbing. Have you tried using the UI builder to remove your button from the tab order? (I don't know what this does to the button under the covers.)

    Or perhaps you can get rid of it by using
    Code:
    QPushButton:selected { 
      border-image: some-image;
    }
    (or some of the other border properties)
    since the rectangle is, as you suggest, likely a part of the border.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    39

    Re: How to get rid of focus rectangle?

    Hi Stegemann,

    Overriding drawControl works well with stylesheets and just requires a few lines of implementation. All the code you need is here.

    Hope that helps

    //Lennart

  6. #6
    Regular Contributor
    Join Date
    May 2009
    Posts
    146

    Re: How to get rid of focus rectangle?

    Quote Originally Posted by lsvensson View Post
    Hi Stegemann,

    Overriding drawControl works well with stylesheets and just requires a few lines of implementation. All the code you need is here.

    Hope that helps

    //Lennart
    Thanks Lennart! So I only need to do this once in the main file and it will work for all QPushbuttons? As I'm running on Symbian I noticed that the example you linked to was using QWindowsStyle, will this still work on my Symbian app?

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    39

    Re: How to get rid of focus rectangle?

    Quote Originally Posted by stegemann View Post
    Thanks Lennart!
    You're welcome!

    So I only need to do this once in the main file and it will work for all QPushbuttons?
    Well, yes, but you need to call setStyle() on each button where you want to get rid of the selection box. I just put it all in a header file, included it and called setStyle() in the constructor of the respective dialog/window as needed.

    As I'm running on Symbian I noticed that the example you linked to was using QWindowsStyle, will this still work on my Symbian app?
    Yes, it was working fine for me on s60 5th/Qt 4.6.2

Similar Threads

  1. WRTkit focus highlight style problems
    By hp3 in forum Symbian
    Replies: 1
    Last Post: 2010-02-16, 08:21
  2. How to get focus on a rectangle drawn through CWindowGc
    By Daaku in forum Symbian User Interface
    Replies: 7
    Last Post: 2009-07-16, 07:58
  3. Set focus to a control
    By logan04x in forum Symbian
    Replies: 7
    Last Post: 2009-01-28, 04:57
  4. Replies: 0
    Last Post: 2006-07-24, 10:43
  5. change focus
    By f_alonso_1 in forum Symbian
    Replies: 0
    Last Post: 2003-07-17, 13:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×