shelllet / cpp-example

c++ examples
24 stars 7 forks source link

请问QTreeWidgetItem::setText()调用后如何实时刷新界面. #3

Open JoneyYang opened 4 years ago

JoneyYang commented 4 years ago

我在调用QTreeWidgetItem::setText()之后,控件的内容并不会立即刷新内容,而是在我鼠标划过之后才会刷新。

shelllet commented 4 years ago

理論上 QTreeWidgetItem::setText(int column, const QString &text) 之後應該不需要刷新。

可以試試 QTreeWidget的update函數

void update(const QModelIndex &index)

Updates the area occupied by the given index.
shelllet commented 4 years ago

很可能是你的顯卡問題,你在什麽系統上做應用?

JoneyYang commented 4 years ago

很可能是你的顯卡問題,你在什麽系統上做應用?

我的环境是 Win10 , Qt 5.14.

我猜测是QT为了效率, 并不会立即绘制Item。 因为我发现,在Tree里面新插入一项,整个 Tree会立即刷新, 但是setText并不会。

update函数我尝试过, 但并没有效果。

shelllet commented 4 years ago

https://youtu.be/c8ZZ6h8rbtE ui->treeWidget->topLevelItem(0)->child(0)->setText(0, ui->lineEdit->text()); Example

shangfire commented 1 year ago

使用dataChanged(QModelIndex(), QModelIndex());