概述
程序运行截图如下:
原理:在Widget上面套一个QGraphicsView,把Widget放入QGraphicsProxyWidget,然后对QGraphicsProxyWidget操作即可!
源码如下:
ddisplaydialog.h
#ifndef DISPLAYDIALOG_H
#define DISPLAYDIALOG_H
#include <QDialog>
QT_BEGIN_NAMESPACE
class QGraphicsScene;
QT_END_NAMESPACE
class SSignalWidget;
class MyCustomProxy;
namespace Ui {
class displayDialog;
}
class displayDialog : public QDialog
{
Q_OBJECT
public:
explicit displayDialog(QWidget *parent = 0);
~displayDialog();
protected:
void initWidget();
protected slots:
void closeGraphicsWindows();
private:
Ui::displayDialog *ui;
QGraphicsScene *m_scene;
SSignalWidget *m_ssignalWidget;
MyCustomProxy *m_myCustomProxy;
};
#endif // DISPLAYDIALOG_H
mycustomproxy.h
#ifndef MYCUSTOMPROXY_H
#define MYCUSTOMPROXY_H
#include <QGraphicsProxyWidget>
QT_BEGIN_NAMESPACE
class QTimeLine;
QT_END_NAMESPACE
class MyCustomProxy : public QGraphicsProxyWidget
{
Q_OBJECT
public:
MyCustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
~MyCustomProxy();
protected slots:
void updateStep(int step);
private:
QTimeLine *m_timeLine;
};
#endif // MYCUSTOMPROXY_H
ssignalwidget.h
#ifndef SSIGNALWIDGET_H
#define SSIGNALWIDGET_H
#include <QWidget>
namespace Ui {
class SSignalWidget;
}
class SSignalWidget : public QWidget
{
Q_OBJECT
public:
explicit SSignalWidget(QWidget *parent = 0);
~SSignalWidget();
protected slots:
void closeWindows();
signals:
void allWindowsClose();
private:
Ui::SSignalWidget *ui;
};
#endif // SSIGNALWIDGET_H
displaaydialog.cpp
#include "displaydialog.h"
#include "ui_displaydialog.h"
#include "mycustomproxy.h"
#include "ssignalwidget.h"
#include <QDebug>
#include <QTransform>
#include <QGraphicsScene>
#include <QEventLoop>
#include <QTimer>
displayDialog::displayDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::displayDialog)
{
ui->setupUi(this);
initWidget();
showFullScreen();
}
displayDialog::~displayDialog()
{
delete ui;
}
void displayDialog::initWidget()
{
this->setWindowTitle("二次包含信号设置对话框");
ui->graphicsView->setStyleSheet("background: transparent;border:0px");
ui->graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->graphicsView->setRenderHints(ui->graphicsView->renderHints()|QPainter::Antialiasing|QPainter::SmoothPixmapTransform);
setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
m_scene = new QGraphicsScene;
m_scene->setSceneRect(-500, -500, 500, 500);
ui->graphicsView->setScene(m_scene);
m_myCustomProxy = new MyCustomProxy;
m_myCustomProxy->setWindowFlags(Qt::Window);
//m_myCustomProxy->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
m_ssignalWidget = new SSignalWidget;
m_scene->addItem(m_myCustomProxy);
m_myCustomProxy->setWidget(m_ssignalWidget);
m_myCustomProxy->setPos(-m_ssignalWidget->width(), -m_ssignalWidget->height());
ui->graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
connect(m_ssignalWidget, SIGNAL(allWindowsClose()), this, SLOT(closeGraphicsWindows()));
}
void displayDialog::closeGraphicsWindows()
{
//延迟下,先让m_ssignalWidget关闭
qDebug()<< "received closeSignal";
QEventLoop loop;
QTimer::singleShot(1000, &loop, SLOT(quit()));
loop.exec();
close();
}
main.cpp
#include "displaydialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
displayDialog w;
w.show();
return a.exec();
}
mycustomproxy.cpp
#include "mycustomproxy.h"
#include <QDebug>
#include <QTransform>
#include <QTimeLine>
MyCustomProxy::MyCustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
: QGraphicsProxyWidget(parent, wFlags)
{
QTransform transform;
setTransform(transform.rotate(90, Qt::XAxis));
m_timeLine = new QTimeLine;
m_timeLine->setFrameRange(90, 0);
m_timeLine->setDuration(1500);
connect(m_timeLine, SIGNAL(frameChanged(int)),this,SLOT(updateStep(int)));
m_timeLine->start();
}
MyCustomProxy::~MyCustomProxy()
{
}
void MyCustomProxy::updateStep(int step)
{
QTransform transform;
setTransform(transform.rotate(step, Qt::XAxis));
}
ssignalwidget.cpp
#include "ssignalwidget.h"
#include "ui_ssignalwidget.h"
#include <QEventLoop>
#include <QDebug>
#include <QTimer>
SSignalWidget::SSignalWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SSignalWidget)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(closeWindows()));
}
SSignalWidget::~SSignalWidget()
{
delete ui;
}
void SSignalWidget::closeWindows()
{
emit allWindowsClose();
QEventLoop loop;
QTimer::singleShot(0.5 * 1000, &loop, SLOT(quit()));
this->close();
}
最后
以上就是安静龙猫为你收集整理的Qt工作笔记-让界面飞一会(让界面旋转出来)的全部内容,希望文章能够帮你解决Qt工作笔记-让界面飞一会(让界面旋转出来)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复