当前位置: 首页 > news >正文

网页快照网站西安印象网站建设

网页快照网站,西安印象网站建设,wordpress的版本号,wordpress局部刷新很多电脑软件都有鼠标拖动一张图片或者拖动一个文件到软件的指定区域内#xff0c;就可以自动在软件中显示图片内容或者文件内容。qt中也可以这样实现。 本文介绍两种方法#xff1a; 1、只可以以非管理员的身份运行软件时#xff0c;才可以实现上述功能。 mainwindow.h#…很多电脑软件都有鼠标拖动一张图片或者拖动一个文件到软件的指定区域内就可以自动在软件中显示图片内容或者文件内容。qt中也可以这样实现。 本文介绍两种方法 1、只可以以非管理员的身份运行软件时才可以实现上述功能。 mainwindow.h#ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindowQT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACEclass MainWindow : public QMainWindow {Q_OBJECTpublic:MainWindow(QWidget *parent nullptr);~MainWindow();//重写下面2个函数来完成接受外来拖拽的操作.void dragEnterEvent(QDragEnterEvent *event);void dropEvent(QDropEvent *event);private:Ui::MainWindow *ui; }; #endif // MAINWINDOW_Hmainwindow.cpp#include mainwindow.h #include ui_mainwindow.h #include QDropEvent #include QMimeDataMainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) {ui-setupUi(this);setAcceptDrops(true); }MainWindow::~MainWindow() {delete ui; }void MainWindow::dragEnterEvent(QDragEnterEvent *event) {if (event-mimeData()-hasUrls()){event-acceptProposedAction();} }void MainWindow::dropEvent(QDropEvent *event) {if (event-mimeData()-hasUrls()){QListQUrl urlList event-mimeData()-urls();if (urlList.size() 1){QString filePath urlList.first().toLocalFile();QPixmap pixmap(filePath);pixmap.scaled(ui-pictureLabel-size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);ui-pictureLabel-setPixmap(pixmap);}}event-acceptProposedAction();event-setDropAction(Qt::MoveAction);event-accept(); }效果 QQ录屏20231225103401 2、以管理员身份运行软件时也可以实现上述的功能。 1、需要在.pro文件中加上两个静态依赖库Ole32.lib User32.lib CustomDragDrap.proQT core guigreaterThan(QT_MAJOR_VERSION, 4): QT widgetsCONFIG c17# You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES QT_DISABLE_DEPRECATED_BEFORE0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES \main.cpp \mainwindow.cppHEADERS \mainwindow.hFORMS \mainwindow.ui# Default rules for deployment. qnx: target.path /tmp/$${TARGET}/bin else: unix:!android: target.path /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS targetwin32:CONFIG(release, debug|release): LIBS -lOle32 else:win32:CONFIG(debug, debug|release): LIBS -lOle32d else:unix: LIBS -lOle32INCLUDEPATH $$PWD/../lib DEPENDPATH $$PWD/../libwin32:CONFIG(release, debug|release): LIBS -lUser32 else:win32:CONFIG(debug, debug|release): LIBS -lUser32d else:unix: LIBS -lUser32INCLUDEPATH $$PWD/../lib DEPENDPATH $$PWD/../lib (2)、在main.cpp中设置允许管理员身份获取拖放事件。 main.cpp#include mainwindow.h#include QApplication #include Windows.h #include QDebugint main(int argc, char *argv[]) {QApplication a(argc, argv);MainWindow w;//处理当以管理员身份运行程序时不能捕捉到文件拖放事件的问题{void* user32 LoadLibraryA(user32);FARPROC func GetProcAddress((HMODULE)user32, ChangeWindowMessageFilter);user32 LoadLibraryA(user32);func GetProcAddress((HMODULE)user32, ChangeWindowMessageFilter);ChangeWindowMessageFilter(WM_DROPFILES, 1);qDebug() w.winId() w.effectiveWinId();ChangeWindowMessageFilterEx((HWND)w.effectiveWinId(), WM_DROPFILES, MSGFLT_ALLOW, NULL);ChangeWindowMessageFilterEx((HWND)w.effectiveWinId(), WM_COPYDATA, MSGFLT_ALLOW, NULL);ChangeWindowMessageFilterEx((HWND)w.effectiveWinId(), 0x0049, MSGFLT_ALLOW, NULL);DragAcceptFiles((HWND)w.effectiveWinId(), true);RevokeDragDrop((HWND)w.winId());}w.show();return a.exec(); }(3)、重写nativeEvent获取拖放事件中的数据 mainwindow.h#ifndef MAINWINDOW_H #define MAINWINDOW_H#include QMainWindowQT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACEclass MainWindow : public QMainWindow {Q_OBJECTpublic:MainWindow(QWidget *parent nullptr);~MainWindow();protected://重新该函数实现捕获系统的拖放事件和数据bool nativeEvent(const QByteArray eventType, void *message, long *result);private:Ui::MainWindow *ui; }; #endif // MAINWINDOW_H mainwindow.cpp#include mainwindow.h #include ui_mainwindow.h #include QMimeData #ifdef Q_OS_WIN #include qt_windows.h #include Windowsx.h #endifMainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow) {ui-setupUi(this);setAcceptDrops(true); }MainWindow::~MainWindow() {delete ui; }bool MainWindow::nativeEvent(const QByteArray eventType, void *message, long *result) {if (eventType windows_generic_MSG){MSG* msg static_castMSG*(message);if (msg-message WM_DROPFILES){*result 0; #ifdef Q_OS_WINMSG* msg reinterpret_castMSG*(message);HDROP dropHandle reinterpret_castHDROP(msg-wParam);int numFiles DragQueryFile(dropHandle, 0xFFFFFFFF, nullptr, 0);if (numFiles 0){//获取鼠标释放时的位置HWND hWnd msg-hwnd;POINT point;GetCursorPos(point);ScreenToClient(hWnd, point);WCHAR filePath[MAX_PATH];DragQueryFileW(dropHandle, 0, filePath, MAX_PATH);// 处理拖入文件的路径QString picturepath QString::fromWCharArray(filePath);//显示图片QPixmap pixmap(picturepath);ui-pictureLabel-setPixmap(pixmap);}DragFinish(dropHandle);return true; #elseQ_UNUSED(message)return false; #endif}}return QWidget::nativeEvent(eventType, message, result); }效果 QQ录屏20231225105502
http://www.pierceye.com/news/294124/

相关文章:

  • 阿里巴巴 网站建设遵义网警
  • 宁夏建设厅网站官网如何做DJ网站
  • 龙岩做网站公司哪家好erp系统与网站对接长沙
  • 做二手房需要用到哪些网站搜集房源找人做设计的网站
  • 建设银行河北分行招聘网站可以下载新闻视频的网站
  • 凡客官网旗舰店襄阳seo关键词优化公司
  • 区域门户网站源码健身网站建设
  • 动漫网站建设赚钱吗三端互通传奇手游开服列表
  • 网站建设前的需求分析手机免费制作网站模板免费下载
  • 网站兼容ie7接私活做网站要不要签合同
  • 广州网站建设首选快优wordpress拖拽建站
  • 网站开发 播放音频amr个人网站设计案例
  • 建设一个网站可以采用那几方案常用的网页制作工具有什么
  • 摄影看图网站河南省交通工程造价信息网
  • 网站架构发展历程的思考和心得体会软件开发网站开发培训
  • 陕西天工建设有限公司网站长安网站建设哪家好
  • 东莞网站的建设重庆妇科医院哪家好医院公立医院
  • 北京用网站模板建站wordpress中文 插件下载
  • 做网站公司哪家正规重庆网站建设重庆
  • 网站转备案申请学校网站建设申请书
  • 宜昌网站建设选择宜昌慧享互动线上店免费推广的软件
  • 网站建设主流语言织梦网站流动广告代码
  • 南京做网站公司哪个网站上做ppt比较好看的
  • 在服务器上搭建网站中国建设银行淮南分行网站
  • 网站建设什么服务器品牌哪个好南京企业制作网站
  • 太原有哪些做网站的公司如何伪原创 网站
  • 设计好的网站网站策划方案详解
  • 建网站潞城哪家强?企业网络推广技巧
  • 怎么建设网站让国外看wordpress 公司内网
  • 虚拟主机购买网站网站值不值得做seo