ツリービューのsetItemDelegateメソッドを使用して、ツリービューアイテムのカスタムペイント手順を設定できます。デリゲートのペイントメソッドでは、アイテムオプションからQStyle :: State_HasFocusスタイルを削除し、基本ペイントルーチンを実行できます。以下は例です。申し訳ありませんが、C++です。
...
NoFocusDelegate* delegate = new NoFocusDelegate();
ui->treeView->setItemDelegate(delegate);
...
class NoFocusDelegate : public QStyledItemDelegate
{
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
};
void NoFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
{
QStyleOptionViewItem itemOption(option);
if (itemOption.state & QStyle::State_HasFocus)
itemOption.state = itemOption.state ^ QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, itemOption, index);
}
update0:カスタムQStyleオブジェクトを使用してTReeViewに溺れることからQFocusFrameを削除します。以下は、アプリケーションオブジェクトに適用されるカスタムQMotifStyleスタイルの子孫(あなたの場合はQMacStyleの子孫であると思います)の例です。qtreeviewウィジェットを検出するたびに、フレームの長方形のペイントは行われません。
class MyStyle1 : public QMotifStyle
{
public:
MyStyle1()
{
//???
}
void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = 0 ) const
{
if (element==CE_FocusFrame)
{
const QFocusFrame* frame = qobject_cast<const QFocusFrame*>(widget);
if (frame && frame->widget())
{
QTreeView* treeView = qobject_cast<QTreeView*>(frame->widget());
if (treeView)
{
qDebug() << "no CE_FocusFrame for QFocusFrame over QTreeViews";
return;
}
}
}
QMotifStyle::drawControl(element, option, painter, widget);
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCDEStyle style;
a.setStyle(new MyStyle1());
//a.setStyle(new QMotifStyle());
MainWindow w;
w.show();
return a.exec();
}
これがお役に立てば幸いです