似乎焦点矩形由正在使用的QStyle(不要与样式表混淆)处理。您可以编写一个QStyle 子类并将其应用于您的QTabWidget。子类应覆盖drawControl() 方法,如果它当前正在绘制焦点矩形,则不执行任何操作。
子类看起来像这样:
NoFocusRectStyle.h
#ifndef NOFOCUSRECTSTYLE_H
#define NOFOCUSRECTSTYLE_H
#include <QWindowsVistaStyle> // or the QStyle subclass of your choice
class NoFocusRectStyle : public QWindowsVistaStyle
{
public:
NoFocusRectStyle();
protected:
void drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget = 0) const;
};
#endif // NOFOCUSRECTSTYLE_H
NoFocusRectStyle.cpp
#include "NoFocusStyle.h"
NoFocusRectStyle::NoFocusRectStyle()
{
}
void NoFocusRectStyle::drawControl(ControlElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget) const
{
if(element == CE_FocusFrame)
return;
QWindowsVistaStyle::drawControl(element, option, painter, widget);
}
在表单的初始化器/构造器中的某个地方,您可以将自定义样式子类应用到选项卡小部件:
ui->tabWidget->setStyle(new NoFocusRectStyle());
这应该允许您的样式表继续工作。
如果有更简单的方法来做到这一点,那就太好了,但我找不到:)