widget.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "widget.h"
  2. #include "./ui_widget.h"
  3. #include <QTimer>
  4. #include <qboxlayout.h>
  5. #include <qtimer.h>
  6. #include "spdlog/spdlog.h"
  7. #include "PlayerGLWidget2.h"
  8. #include "WidgetGL1.h"
  9. #include "WidgetGL2.h"
  10. #include "WidgetGL3.h"
  11. Widget::Widget(QWidget *parent)
  12. : QWidget(parent)
  13. , ui(new Ui::Widget)
  14. {
  15. ui->setupUi(this);
  16. // m_playerGLWidget = new PlayerGLWidget(this);
  17. // m_playerGLWidget->setGeometry(0, 0, ui->widget_display->width(), ui->widget_display->height());
  18. // m_playerGLWidget->setStyleSheet(R"(border-radius:10px;)");
  19. // /* 设置背景颜色 */
  20. // this->setAutoFillBackground(true);
  21. // QPalette palette = m_playerGLWidget->palette();
  22. // palette.setColor(QPalette::Window, Qt::black); // 设置背景颜色为黑色
  23. // this->setPalette(palette);
  24. // QImage image = QImage(":/image/1.jpg");
  25. // connect(&m_timer, &QTimer::timeout, this, [=]() {
  26. // // SPDLOG_DEBUG("刷新一帧");
  27. // m_playerGLWidget->testShowYUV420Image(image); // 显示一张测试图片
  28. // });
  29. // m_timer.setSingleShot(false);
  30. // m_timer.start(10); // 60 FPS
  31. QVBoxLayout* vLayout = new QVBoxLayout(ui->widget_display);
  32. vLayout->setContentsMargins(0, 0, 0, 0);
  33. m_gl1 = new WidgetGL3(ui->widget_display);
  34. vLayout->addWidget(m_gl1);
  35. QTimer* timer = new QTimer(this);
  36. connect(timer, &QTimer::timeout, this, [=]() {
  37. m_gl1->update();
  38. });
  39. timer->start(100); // approximately 30 FPS
  40. }
  41. Widget::~Widget()
  42. {
  43. delete ui;
  44. }
  45. void Widget::resizeEvent(QResizeEvent *event)
  46. {
  47. if (m_playerGLWidget) {
  48. m_playerGLWidget->setGeometry(0, 0, ui->widget_display->width(), ui->widget_display->height());
  49. }
  50. QWidget::resizeEvent(event);
  51. }