• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

本人开发了一个傅立叶周期分析软件,可以对股票、基金、期货、外汇等数据进行周期分析和趋势分析。关注微信微信官方账号:QStockView

1.1附带的框架。QT系统可以实现拖动和改变大小的功能。但是在某些场景下,程序系统的标题栏要定制,系统自带的框架的标题栏要隐藏起来,设置成框架的形式。这时候就需要自定义拖动,改变窗框的大小;

jvbko2mkc5s3740.png

实现理念

(1)将主窗口从上到下分为1、2、3,从左到右分为1、2、3,使之成为一个九宫格;在鼠标的外边缘区域,鼠标自动变成双箭头的形式,每个区域的鼠标箭头方向也不同。您可以拖动边框来更改大小。在其他区域,鼠标是正常的小箭头图标;

(2)根据鼠标在不同区域是否被按下,并根据按下的相对位移,重新计算窗口的大小,进而调整窗口大小。

2.实施步骤

定义头文件变量和函数

#ifndef FULIYEPERIOD_H

#定义FULIYEPERIOD_H

#包含QtWidgets/QMainWindow

#include 'ui_dftAnalyze.h '

#包含“NGraph.hpp”

#包含QAxObject

#定义框架形状10

枚举{

TOPLEFT=11,

TOP=12,

TOPRIGHT=13,

左=21,

中心=22,

右=23,

BUTTOMLEFT=31,

BUTTOM=32,

BUTTOMRIGHT=33

};

:公共主窗口

{

q _对象

公共:

FuliyePeriod(q widget * parent=0);

~ FuliyePeriod();

void mousePressEvent(QMouseEvent * event);

void mouseReleaseEvent(QMouseEvent * event);

void mouseDoubleClickEvent(QMouseEvent * event);

void mouseMoveEvent(QMouseEvent * event);

int calcorsorcol(q point pt);//计算鼠标X在1,2,3哪个区域的位置。

int CalCursorPos(QPoint pt,int col pos);//用十位数表示Y在1,2,3哪个区域的位置

void setCursorShape(int CalPos);//设置相应的鼠标位置11,12,13,21,22,23,31,32,33来设置鼠标的形状。

private:

Ui:FlyAnalyze uiint m _ iCalCursorPos

bool m _ bLeftPress

QRect m _ rtPreGeometry

QPoint m _ ptViewMousePos

};

#endif //FULIYEPERIOD_H

源文件实现功能

void fuliyeperiod : mousepresevent(QMouseEvent *事件)

{

q point pos 2=qcursor :3360 pos();

pos 2=this-mapFromGlobal(q cursor()。pos());//全局坐标转换为主窗口的相对坐标。

m _ iCalCursorPos=calcorsorpos(pos 2,calcorsorcol(pos 2));

if(event-button()==Qt : left button/* Qt : window maximized!=windowState()*/)

{

if (m_iCalCursorPos!=中心)

{

m _ bLeftPress=true

}

}

m _ rtPreGeometry=geometry();

m _ ptViewMousePos=event-global pos();

}

void fuliyeperiod : mousemoveevent(QMouseEvent *事件)

{

//如果窗体不是最大的,则更改鼠标的形状。

QPoint pos2=QCursor:

pos(); pos2 = this->mapFromGlobal(QCursor().pos()); if (Qt::WindowMaximized != windowState()) { setCursorShape(CalCursorPos(pos2, CalCursorCol(pos2))); } //获取当前的点,这个点是全局的 QPoint ptCurrentPos = QCursor::pos(); //计算出移动的位置,当前点 - 鼠标左键按下的点 QPoint ptMoveSize = ptCurrentPos - m_ptViewMousePos; QRect rtTempGeometry = m_rtPreGeometry; if (m_bLeftPress) { switch (m_iCalCursorPos) { case TOPLEFT: rtTempGeometry.setTopLeft(m_rtPreGeometry.topLeft() + ptMoveSize); break; case TOP: rtTempGeometry.setTop(m_rtPreGeometry.top() + ptMoveSize.y()); break; case TOPRIGHT: rtTempGeometry.setTopRight(m_rtPreGeometry.topRight() + ptMoveSize); break; case LEFT: rtTempGeometry.setLeft(m_rtPreGeometry.left() + ptMoveSize.x()); break; case RIGHT: rtTempGeometry.setRight(m_rtPreGeometry.right() + ptMoveSize.x()); break; case BUTTOMLEFT: rtTempGeometry.setBottomLeft(m_rtPreGeometry.bottomLeft() + ptMoveSize); break; case BUTTOM: rtTempGeometry.setBottom(m_rtPreGeometry.bottom() + ptMoveSize.y()); break; case BUTTOMRIGHT: rtTempGeometry.setBottomRight(m_rtPreGeometry.bottomRight() + ptMoveSize); break; default: break; } //移动窗体,如果比最小窗体大,就移动 if (rtTempGeometry.width() >= 200 && rtTempGeometry.height() >= 300) setGeometry(rtTempGeometry); } } void FuliyePeriod::mouseReleaseEvent(QMouseEvent * event) { m_bLeftPress = false; QApplication::restoreOverrideCursor(); }

 

3.参考文献,修改了一些缺陷;

https://blog.csdn.net/weixin_40222745/article/details/82142333

 

#ifndef FULIYEPERIOD_H#define FULIYEPERIOD_H
#include <QtWidgets/QMainWindow>#include "ui_dftAnalyze.h"#include"NGraph.hpp"#include <QAxObject>
#define FRAMESHAPE 10 enum {TOPLEFT = 11,TOP = 12,TOPRIGHT = 13,LEFT = 21,CENTER = 22,RIGHT = 23,BUTTOMLEFT = 31,BUTTOM = 32,BUTTOMRIGHT = 33};
class FuliyePeriod : public QMainWindow{Q_OBJECT
public:FuliyePeriod(QWidget *parent = 0);~FuliyePeriod();//int dftAnalyzeStock(QString strCode);//void mousePressEvent(QMouseEvent *event);//void mouseReleaseEvent(QMouseEvent *event);//void mouseDoubleClickEvent(QMouseEvent *event);void mousePressEvent(QMouseEvent *event);void mouseReleaseEvent(QMouseEvent *event);void mouseDoubleClickEvent(QMouseEvent *event);void mouseMoveEvent(QMouseEvent *event);int CalCursorCol(QPoint pt);    //个位计算鼠标X的在1,2,3哪个区域位置位置 int CalCursorPos(QPoint pt, int colPos);    //用十位表示y在1,2,3哪个区域的位置void setCursorShape(int CalPos);    //设置鼠标对应位置11,12,13,21,22,23,31,32,33设置鼠标的形状//void showEvent(QShowEvent *e);public slots:void dftAnalyzeStock();void InputExcelData();void SlotWaringDialog(int errorcode, QString strContent);private:Ui::FlyAnalyze ui;NGraph m_original;NGraph* m_graph = NULL;int m_topN = 5;QString m_strCode;QFrame m_lineVertival;QString m_defalutPath = "";bool m_leftMousePressed=false;QPoint m_StartPoint;int     m_iCalCursorPos;bool    m_bLeftPress;QRect   m_rtPreGeometry;QPoint  m_ptViewMousePos;};
#endif // FULIYEPERIOD_H
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now