• 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

QT自定义关闭 放大和缩小按钮标题栏


Recommended Posts

本人开发了一个傅立叶周期分析软件,可以对股票、基金、期货、外汇等数据进行周期分析和趋势分析。

1.问题的原因

因为改变Qt程序标题栏的颜色皮肤,添加平视指令和授权指令都比较困难,但是QT自己的标题栏颜色好像是改不了的,添加新的按钮文字就更难了,所以需要自定义一个程序的标题栏。如下图所示。

l1fmychydfj3787.png

2.实施步骤

2.1自定义标题栏界面

133lkwrqibp3788.png

2.2隐藏系统本身的标题栏。

//设置为无边框,自定义关闭、放大、缩小按钮。

this-setWindowFlags(Qt :3360 frameleswindowhint);

2.3实现关闭、最大化、最小化和按钮响应。

//顶部按钮响应

connect(ui.pBClose,QPushButton:clicked,[=](){ close();});

connect(ui.pBMaxWindow,QPushButton:clicked,[=]()

{ if (this-isMaximized())

{

this-show normal();

}

其他

{

this-show maximized();

}

});

connect(ui.pBMinWindow,QPushButton:clicked,[=](){ this-show minimized();});

2.4按住标题栏,拖动窗口移动。

系统自带的标题栏可以按住鼠标左键拖动窗口,这个功能在这里要打折扣。

通过按鼠标来确定鼠标是否在标题栏上。如果是,将鼠标左键设置为true。鼠标移动函数确定鼠标是否被按下,计算鼠标的实时位置,与初始位置进行比较,计算鼠标移动的相对位移。然后,将相对位移添加到主窗口的坐标上,然后移动主窗口以更新初始位置。在鼠标释放函数中,只需将左键down的布尔值设置为false即可;

void fuliyeperiod : mousepresevent(QMouseEvent *事件)

{

//只有鼠标左键可以移动和改变大小

if(event-button()==Qt : left button)

{

if (ui.widgetToolBar-underMouse())

{

m _ leftMousePressed=true

//当鼠标左键被按下时,窗口在屏幕中的坐标。

m _ start point=event-global pos();

}

}

}

void fuliyeperiod : mousemoveevent(QMouseEvent *事件)

{//移动窗口

if (m_leftMousePressed)

{

q point curPoint=event-global pos();//移动时按住位置

q point move point=cur point-m _ start point;

//普通窗口

q point mainWinPos=this-pos();

this-move(mainwinpos . x()move point . x()、mainwinpos . y()move point . y());

m _ StartPoint=curPoint

}

}

void fuliyeperiod : mousereaseevent(QMouseEvent * event)

{

m _ leftMousePressed=false//释放鼠标

}

最后实现了按住标题栏拖动主窗口的功能。另一个问题是系统框架可以拖动调整大小的功能。我们将回到下一节来看如何实现它。

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