基本信息
源码名称:Qt组态源码
源码大小:3.60KB
文件格式:.rar
开发语言:C/C++
更新时间:2016-07-14
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
#include "mainform.h" #include "ui_mainform.h" #include <QKeyEvent> MainForm::MainForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainForm) { ui->setupUi(this); setWindowOpacity(1); setWindowFlags(Qt::FramelessWindowHint); setAttribute(Qt::WA_TranslucentBackground); m_actOrn = new QAction("垂直", this); connect(m_actOrn, SIGNAL(triggered()), SLOT(onOrn())); m_actAlign = new QAction("对齐", this); connect(m_actAlign, SIGNAL(triggered()), SLOT(onAlign())); addAction(m_actOrn); addAction(m_actAlign); setContextMenuPolicy(Qt::ActionsContextMenu); ui->ruler->setOrientation(Qt::Horizontal); resize(ui->ruler->sizeHint()); connect(ui->ruler, SIGNAL(moved(QPoint)), SLOT(onMove(QPoint))); } MainForm::~MainForm() { delete ui; } void MainForm::onMove(QPoint p) { move(pos() p); } void MainForm::onOrn() { if (m_actOrn->text() == "垂直") { ui->ruler->setOrientation(Qt::Vertical); m_actOrn->setText("水平"); } else { ui->ruler->setOrientation(Qt::Horizontal); m_actOrn->setText("垂直"); } resize(ui->ruler->sizeHint()); update(); } void MainForm::onAlign() { m_actOrn->text() == "垂直" ? move(0, pos().y()) : move(pos().x(), 0); } void MainForm::keyReleaseEvent(QKeyEvent *e) { QPoint p = pos(); if (e->key() == Qt::Key_Left) p = QPoint(-1,0); else if (e->key() == Qt::Key_Right) p = QPoint(1,0); else if (e->key() == Qt::Key_Up) p = QPoint(0,-1); else if (e->key() == Qt::Key_Down) p = QPoint(0,1); move(p); }