QListWidget::addItem 产生可怕的闪烁
当我一次添加一项(添加一项然后返回到事件循环)时会发生这种情况。为了说明这一点,我的代码大致如下所示:
.................... timer = new QTimer(this); timer->setInterval(0); connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout())); .................... void Dialog::onTimeout() { QListWidgetItem* item = new QListWidgetItem; .................... ui->listWidget->addItem(item); }
This happens when I add items one at a time (adding one item and then returning to the event loop). To illustrate, my code looks roughly like this:
.................... timer = new QTimer(this); timer->setInterval(0); connect(timer, SIGNAL(timeout()), this, SLOT(onTimeout())); .................... void Dialog::onTimeout() { QListWidgetItem* item = new QListWidgetItem; .................... ui->listWidget->addItem(item); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码对我来说看起来不错。我在本地计算机上运行它并且执行时没有闪烁。您是否正在处理密集的图形(即使这应该没问题,因为 Qt 定义 timeout(0)...因为它等待事件队列完成)?最有可能的是其他代码是罪魁祸首。
The code look OK to me. I ran it on my local machine and it executed without flickering. Are you dealing with intense graphics (even this should be OK due to the way Qt defines timeout(0)... as it waits for event queue to complete)? Most likely there is other code that is the culprit.