QListWidget on mac os X 显示异常

QListWidget on mac os X show abnormal

我在 mac 的 Qt Creator 上使用 QListWidget,这是我的代码

m_pListWidget->setObjectName(QStringLiteral("ttmanagevmlist"));
m_pListWidget->setFrameShape(QListWidget::NoFrame);
m_pListWidget->setAttribute(Qt::WA_TranslucentBackground,false);
m_pListWidget->setAlternatingRowColors(true);
m_pListWidget->setContentsMargins(0,0,0,0);
m_pListWidget->setResizeMode(QListView::Fixed);
m_pListWidget->setAutoScroll(true);
m_pListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);

但是显示不正常,像这样

它有蓝色边框,但是当它失去焦点时,这是正常的。谁知道问题的原因?

我相信你可以使用这个:

m_pListWidget->setAttribute(Qt::WA_MacShowFocusRect, false);

了解 Qt::WA_MacShowFocusRect here

Indicates that this widget should get a QFocusFrame around it. Some widgets draw their own focus halo regardless of this attribute. Not that the QWidget::focusPolicy also plays the main role in whether something is given focus or not, this only controls whether or not this gets the focus frame. This attribute is only applicable to OS X.