QListWidget::addItem 产生可怕的闪烁

发布于 2024-10-06 18:17:05 字数 392 浏览 0 评论 0原文

当我一次添加一项(添加一项然后返回到事件循环)时会发生这种情况。为了说明这一点,我的代码大致如下所示:

    ....................
    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-10-13 18:17:05

该代码对我来说看起来不错。我在本地计算机上运行它并且执行时没有闪烁。您是否正在处理密集的图形(即使这应该没问题,因为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文