View Full Version : How to hide dotted lines around the focused control?
gimel
5th November 2008, 15:58
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.
gimel
6th November 2008, 03:45
Digged thru Qt sources, found a solution for Vista:
class CheckBoxStyleNoFocusDrawVista: public QWindowsVistaStyle{
public:
void drawControl(ControlElement element, const QStyleOption *opt,
QPainter *p, const QWidget *widget) const
{
switch (element) {
case CE_CheckBox:
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
QStyleOptionButton subopt = *btn;
subopt.rect = subElementRect(SE_CheckBoxIndicator, btn, widget);
drawPrimitive(PE_IndicatorCheckBox, &subopt, p, widget);
subopt.rect = subElementRect(SE_CheckBoxContents, btn, widget);
drawControl(CE_CheckBoxLabel, &subopt, p, widget);
}
break;
default:
QWindowsVistaStyle::drawControl(element, opt, p, widget);
}
}
};
void CheckBox1::CheckBox1():QCheckBox(){
setStyle(new CheckBoxStyleNoFocusDraw());
}
This needs to be extended for all operating systems (Windows, XP, Vista, Mac).
gimel
6th November 2008, 04:17
Here's a convinience function for determining Windows version:
typedef enum {Vista, Windows, XP} WindowsVersion;
WindowsVersion getWindowsVersion(){
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ){
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
return Windows;//default
}
switch (osvi.dwPlatformId){
case VER_PLATFORM_WIN32_NT:
if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
return XP;
if ( osvi.dwMajorVersion >= 6 )
return Vista;
}
return Windows;
}
class CheckBoxStyleNoFocusDraw_XP: public QWindowsXPStyle{...}
class CheckBoxStyleNoFocusDraw_Windows: public QWindowsStyle{...}
aamer4yu
6th November 2008, 07:09
How about using QSysInfo::WindowsVersion for determining windows version ?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.