Qt:如何使半透明,无窗,无铬窗口可拖动
Qt: How to make translucent, windowless, chromeless window draggable?
我有一个基于半透明图像的窗口:
import QtQuick 1.1
import QtWebKit 1.1
Image {
source: "qrc:/assets/bg.png"
}
主窗口中有类似的东西
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
setAttribute(Qt::WA_TranslucentBackground);
setStyleSheet("background:transparent;");
/* turn off window decorations */
setWindowFlags(Qt::FramelessWindowHint);
ui = new QDeclarativeView;
ui->setSource(QUrl("qrc:/assets/ui.qml"));
setCentralWidget(ui);
}
MainWindow::~MainWindow()
{
delete ui;
}
和
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtDeclarative/QDeclarativeView>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QDeclarativeView *ui;
};
#endif // MAINWINDOW_H
我想知道如何使我的窗口可在屏幕上拖动(用户按下图像和药物窗口..)?
重新实现mousePressEvent()
并mouseReleaseEvent()
知道用户何时按住鼠标,然后重新实现mouseMoveEvent()
如果用户按住鼠标,则移动小部件。
// **Untested code**
protected:
virtual void mousePressEvent(QMouseEvent *event) { _mouseIsDown = true; }
virtual void mouseReleaseEvent(QMouseEvent *event) { _mouseIsDown = false; }
virtual void mouseMoveEvent(QMouseEvent *event) { if(_mouseIsDown) { move(event->pos() + globalPos()); } }
#include <QMouseEvent>
#include <Qpoint>
class MainWindow : public QMainWindow{
...
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
QPoint LastPoint;
QPoint LastTopLeft;
void mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
QPoint Point=event->globalPos();
LastTopLeft=this->frameGeometry().topLeft();
LastPoint=Point;
}
}
void mouseMoveEvent(QMouseEvent *event)
{
if ((event->buttons() & Qt::LeftButton)) {
const QPoint Point=event->globalPos();
QPoint offset=Point-LastPoint;
this->move(LastTopLeft+offset);
}
}
...
}
在我删除前两个声明后,它对我有用。
相关文章:
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 如何在鼠标挂钩过程中检测拖动
- Qt - 防止在拖动标题栏时调整窗口大小
- 如何在QT中拖动未装饰的窗口
- C++可拖动的无边框窗口问题
- MFC单击并移动/拖动对话框窗口
- 当在拖动/调整窗口大小的同时对窗口调用isActive()时,返回false.(X11,问题5.4.0)
- 奇怪的行为逐像素 3d 图形程序 [通过拖动窗口加快绘图速度]
- Qt:如何使半透明,无窗,无铬窗口可拖动
- Qt5-如何在无框窗口中指定一些可拖动区域
- Qt:如何访问在主窗口上按id拖动的元素
- 如何阻止Windows在拖动窗口或按住菜单按钮时阻塞程序?< / h1 >
- 使用ReadConsoleInput()拖动控制台窗口
- 使用 WS_EX_NOACTIVATE 标志创建一个窗口,但在我释放鼠标之前无法拖动它
- 修改win32窗口拖动/移动行为
- 使用SwapMouseButton(TRUE);允许右键拖动窗口
- 如何在OpenGL/c++中拖动窗口周围的图形
- 在 qml 中拖动无框窗口"jiggles"
- 如何通过一定的组合键+鼠标移动来调整窗口大小?(如 Linux 中的 Alt+F8)不要单击并拖动
- 如何在拖动窗口时覆盖默认的 linux Alt+鼠标行为