PDA

View Full Version : How can i avoid QPushButton Focus Rectangle



nightroad
3rd October 2010, 19:01
Hi there,

I have a trouble with annoying Focus Rectangle on Windows, I found http://developer.qt.nokia.com/faq/answer/how_can_i_avoid_drawing_the_focus_rect_on_my_butto ns that link for avoid Focus Rect on Buttons but it's not working for me actually. I'm using arrow keys for navigate on the form elements like buttons but when focused a button there is appearing a rectangle on button , someone have an idea for this problem. Thx ...

squidge
3rd October 2010, 19:25
You'll need to draw the control yourself then, but the idea of the focus rect to make navigating your application without the mouse easier.

nightroad
3rd October 2010, 20:30
You'll need to draw the control yourself then, but the idea of the focus rect to make navigating your application without the mouse easier.

Well thx for answer but could you give me piece of code about drawing control myself. By the way i'm using Stylesheets for focus event i'm highlighting buttons with setting new backcolor. So there ll be no mouse in my application also Focus rect is looking so ugly in my interface ...

SixDegrees
3rd October 2010, 22:49
As already noted, if you're going to build your own interface, you'll have to...build your own interface. By drawing it from scratch. There are plenty of tutorials in the Qt documentation that can guide you.

However, note that this generally isn't a good idea. People get used to their native interface, and get disturbed when it stops working the way it usually does. It's better to focus your energies on ensuring that what your program actually does, it does well, and leave the user interface issues to the operating system.

squidge
3rd October 2010, 23:24
Well thx for answer but could you give me piece of code about drawing control myself. You can subclass whatever controls you need to draw your self, and well, you have the ultimate source code - the code to the Qt library itself, so you can see exactly how it does it. Plus, there is lots of examples in the distribution too.

nightroad
4th October 2010, 06:41
if you're going to build your own interface, you'll have to...build your own interface.
lol thx for good explanation (; ...


It's better to focus your energies on ensuring that what your program actually does,

Tbh, my program working well, atm i have to make a good user experience as i said i'll hide mouse pointer on the application so i have to navigate buttons with arrow keys there is just a problem for me atm annoying focus rect ...

Anyway Thanks for help. i'm new on qt and i'm gonna digging it ...

Lykurg
4th October 2010, 07:28
search the forum. This is a question coming up very often. Mostly for graphics view, but you can use it for normal widgets as well. No custom painting is needed. Just remove the hasfocus flag before redirecting to to the original paint method.

squidge
4th October 2010, 08:08
The link in the first post uses the hasfocus flag, but the OP stated that this didn't work for him, so the only other suggestion is custom painting, surely?

Lykurg
4th October 2010, 10:06
The link in the first post uses the hasfocus flag, but the OP stated that this didn't work for himYes, true, but then he should say what does not work for him, because it works. Also a possibility is to subclass QPushButton direct instead of using a style. (Even better would be a proxystyle.)