需求1做一个主窗口中有一个视频区域,平时放视频,特定条件下显示图片
stackWidget = new QStackedWidget((QWidget *)parent_);
QWidget *w1,*w2;
w1 = new QWidget();
w1->setObjectName("video");
w2 = new QWidget();
w1->setObjectName("linemap");
stackWidget->setObjectName("stackWidget");
stackWidget->addWidget(w1);
stackWidget->addWidget(w2);
stackWidget->setGeometry(QRect(item->x(), item->y(), item->w(), item->h()));
第一个页面放视频,第二个页面显示图片
lineMap = w2;
Qt::WindowFlags flags = 0;//this->windowFlags();
flags |= Qt::CustomizeWindowHint;
flags |= Qt::FramelessWindowHint;
lineMap->setWindowFlags(flags); //不是必需
lineMap->setAutoFillBackground(true);//必需要加
设置QWidget显示背景图
QPixmap pixmap(CONFIG->resource_path + QString("line%1.png").arg(id));
QPalette palette;
palette.setBrush(lineMap->backgroundRole(), QBrush(pixmap));
lineMap->setPalette(palette);
需求2 全屏来回切换显示
stackedWidget = new QStackedWidget(NULL);
atsAWidget = new QWidget(NULL);
atsBWidget = new QWidget(NULL);
atsCWidget = new QWidget(NULL);
stackedWidget->addWidget(atsAWidget);
stackedWidget->addWidget(atsBWidget);
stackedWidget->addWidget(atsCWidget);
stackedWidget->setCurrentIndex(0);
Qt::WindowFlags flags = 0;//this->windowFlags();
flags |= Qt::CustomizeWindowHint;
flags |= Qt::FramelessWindowHint;
flags |= Qt::Window;
atsAWidget->setWindowFlags(flags);
atsBWidget->setWindowFlags(flags);
atsCWidget->setWindowFlags(flags);
atsAWidget->setGeometry(0,0,1920,1080);
atsBWidget->setGeometry(0,0,1920,1080);
atsCWidget->setGeometry(0,0,1920,1080);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(stackedWidget);
this->setLayout(layout);
stackedWidget->setObjectName("stackedWidget");
atsAWidget->setObjectName("atsAWidget");
atsBWidget->setObjectName("atsBWidget");
atsCWidget->setObjectName("atsCWidget");
atsAWidget->showFullScreen();//全屏显示,3个里只能选一个先,显示哪个,
到要切哪个页全屏时
stackedWidget->setCurrentIndex(2);
atsCWidget->showFullScreen();
实际效果感觉有明显的切换痕迹,不知如何优化