Results 1 to 4 of 4

Thread: How to hide dotted lines around the focused control?

  1. #1
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default How to hide dotted lines around the focused control?

    I have a question: how to hide dotted lines around the focused control (in our app, we show focus as blue bar under the control)? I didn't experiment with stylesheets yet. We need to support Windows and Mac.

  2. #2
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Arrow Re: How to hide dotted lines around the focused control?

    Digged thru Qt sources, found a solution for Vista:

    Qt Code:
    1. class CheckBoxStyleNoFocusDrawVista: public QWindowsVistaStyle{
    2. public:
    3. void drawControl(ControlElement element, const QStyleOption *opt,
    4. QPainter *p, const QWidget *widget) const
    5. {
    6. switch (element) {
    7. case CE_CheckBox:
    8. if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
    9. QStyleOptionButton subopt = *btn;
    10. subopt.rect = subElementRect(SE_CheckBoxIndicator, btn, widget);
    11. drawPrimitive(PE_IndicatorCheckBox, &subopt, p, widget);
    12. subopt.rect = subElementRect(SE_CheckBoxContents, btn, widget);
    13. drawControl(CE_CheckBoxLabel, &subopt, p, widget);
    14. }
    15. break;
    16. default:
    17. QWindowsVistaStyle::drawControl(element, opt, p, widget);
    18. }
    19. }
    20. };
    21.  
    22. void CheckBox1::CheckBox1():QCheckBox(){
    23. setStyle(new CheckBoxStyleNoFocusDraw());
    24. }
    To copy to clipboard, switch view to plain text mode 

    This needs to be extended for all operating systems (Windows, XP, Vista, Mac).

  3. #3
    Join Date
    Oct 2008
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to hide dotted lines around the focused control?

    Here's a convinience function for determining Windows version:

    Qt Code:
    1. typedef enum {Vista, Windows, XP} WindowsVersion;
    2.  
    3. WindowsVersion getWindowsVersion(){
    4. OSVERSIONINFOEX osvi;
    5. BOOL bOsVersionInfoEx;
    6. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    7. osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    8.  
    9. if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ){
    10. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    11. if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
    12. return Windows;//default
    13. }
    14.  
    15. switch (osvi.dwPlatformId){
    16. case VER_PLATFORM_WIN32_NT:
    17.  
    18. if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
    19. return XP;
    20.  
    21. if ( osvi.dwMajorVersion >= 6 )
    22. return Vista;
    23. }
    24. return Windows;
    25. }
    26.  
    27. class CheckBoxStyleNoFocusDraw_XP: public QWindowsXPStyle{...}
    28.  
    29. class CheckBoxStyleNoFocusDraw_Windows: public QWindowsStyle{...}
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to hide dotted lines around the focused control?

    How about using QSysInfo::WindowsVersion for determining windows version ?

  5. The following user says thank you to aamer4yu for this useful post:

    gimel (6th November 2008)

Tags for this Thread

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.