---
title: "QTableWidget的openPersistentEditor去掉高亮选择"
author: "johnsmith9th"
date: "2021-08-02T10:59:41Z"
tags: ["QTableWidget", "高亮"]
categories: ["编程语言"]
slug: "qtablewidget-openpersistenteditor"
draft: false
lastmod: "2021-08-02T10:59:41Z"
id: 2520596
url: "https://johnsmith9th.iteye.com/blog/2520596"
---

如果用QTableWidget作为一个表格编辑控件的话，简单的做法就是openPersistentEditor，但是缺省的编辑器如果是文本框或SpinBox的话会高亮选择内容，这个比较讨厌。可以用如下代码将高亮选择去掉：

QList&lt;QLineEdit\*&gt; lstLineEditors = ui.m\_pTableWidget-&gt;findChildren&lt;QLineEdit\*&gt;();

foreach(QLineEdit* pLineEdit, lstLineEditors)

{

pLineEdit-&gt;deselect();

pLineEdit-&gt;clearFocus();

}

 

SpinBox类似不赘述。