从 glwidget 更新 Qt4 状态栏

发布于 2024-09-07 09:02:31 字数 474 浏览 1 评论 0原文

我有一个包含 QGLWidgetQStatusBar 的窗口。我计算 timerEvent 调用内的 fps,但我不知道更新每帧状态栏的“正确”方法。 fpsGLWidget的成员变量:

void GLWidget::timerEvent(QTimerEvent* event){

    updateGL();

    // Calculate FPS.
    prevTime = currentTime;
    currentTime = runTime.elapsed();

    int timeDiff = currentTime - prevTime;

    fps = 1000.0/timeDiff;

    // Update statusbar with fps here.

}

谢谢!

I've got a window containing a QGLWidget and a QStatusBar. I calculate the fps inside a timerEvent call, but I don't know the 'correct' way to update the statusbar on every frame. fps is a member variable of GLWidget:

void GLWidget::timerEvent(QTimerEvent* event){

    updateGL();

    // Calculate FPS.
    prevTime = currentTime;
    currentTime = runTime.elapsed();

    int timeDiff = currentTime - prevTime;

    fps = 1000.0/timeDiff;

    // Update statusbar with fps here.

}

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

初熏 2024-09-14 09:02:31

您可能想要的是连接到的 GLWidget 上的自定义信号。在包含 GLWidget 和状态栏的小部件上建立连接:

connect(&glWidgetInstance, SIGNAL(updateFPSSignal(int)), this, SLOT(updateFPSSlot(int)));

槽函数看起来像这样:

void updateFPSSlot(int fps) {
    // Update status bar
}

请注意,如果状态栏是自定义类,则可以在该类中创建槽函数,并直接连接到它。无论哪种方式,都应该在包含 GLWidget 和状态栏实例的类中进行连接。

What you probably want is a custom signal on the GLWidget that you connect to a slot. Make the connection on the widget containing both the GLWidget and the status bar:

connect(&glWidgetInstance, SIGNAL(updateFPSSignal(int)), this, SLOT(updateFPSSlot(int)));

The slot function would look something like this:

void updateFPSSlot(int fps) {
    // Update status bar
}

Note that if the status bar is a custom class, you can create the slot function in that class, and connect directly to it. Either way, the connection should be made within the class that contains the instances for both the GLWidget and the status bar.

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