资源简介
windows桌面程序靠边自动隐藏,支持多屏幕。通过宏可以自定义隐藏边界border设置和隐藏后边界剩余
代码片段和文件信息
#include “deskdockwidget.h“
#include
#include
#include
#define TEST_BIT(a b) a & b
#define HIDE_BORDER 1 //隐藏时显示border
#define CHECK_BORDER 2 //边界检测宽度
FloatingWidget::FloatingWidget(FloatingFeature D QWidget * parent Qt::WindowFlags flags)
: QWidget(parent flags)
m_feature(D)
{
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::Tool | Qt::framelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground true);
setMouseTracking(true);
}
void FloatingWidget::MoveWindow(const QPoint & start const QPoint & end unsigned int step)
{
QPoint distance = end - start;
QPoint stepPos stepOne;
if (end.x() == start.x())
{
stepOne.setY(step * (distance.y() > 0 ? 1 : -1));
}
else
{
stepOne.setX(step * (distance.x() > 0 ? 1 : -1));
}
stepPos = stepOne;
int disLenght = distance.manhattanLength();
while (stepPos.manhattanLength() <= disLenght)
{
move(start + stepPos);
stepPos += stepOne;
}
move(end);
m_RecoverPosition = start;
}
void FloatingWidget::setDirection(FloatingFeature D)
{
m_feature = D;
}
void FloatingWidget::paintEvent(QPaintEvent *e)
{
QPainter p(this);
QPixmap img(“:/images/m.png“);
p.setBrush(QBrush(img));
p.setPen(QColor(“#b5b4c9“));
p.drawRoundedRect(00width() - 1height() - 1 8 8);
}
void FloatingWidget::HideDockWidget()
{
if (m_IsVisible == false)
{
return;
}
m_IsVisible = false;
int curHeight = height();
int curWidth = width();
QDesktopWidget * desktop = qApp->desktop();
QRect rect = desktop->screenGeometry(this);
if (frameGeometry().left() - CHECK_BORDER <= rect.top()
&& TEST_BIT(m_feature LeftArea))
{
MoveWindow(pos() pos() - QPoint(curWidth - HIDE_BORDER 0));
}
else if (frameGeometry().right() + CHECK_BORDER >= rect.right()
&& TEST_BIT(m_feature RightArea))
{
MoveWindow(pos() pos() + QPoint(curWidth - HIDE_BORDER 0));
}
else if (frameGeometry().top() - CHECK_BORDER <= rect.top()
&& TEST_BIT(m_feature TopArea))
{
MoveWindow(pos() pos() - QPoint(0 curHeight - HIDE_BORDER));
}
else
{
m_IsVisible = true;
}
if (m_IsVisible == false)
{
if (m_timer && m_timer->isActive())
{
m_timer->stop();
}
}
}
void FloatingWidget::ShowDockWidget()
{
if (m_IsVisible)
{
return;
}
m_IsVisible = true;
int curHeight = height();
int curWidth = width();
QDesktopWidget * desktop = qApp->desktop();
QRect rect = desktop->screenGeometry(this);
QRect frameRect = frameGeometry();
if (frameRect.left() == m_RecoverPosition.x() - (curWidth - HIDE_BORDER)
&& TEST_BIT(m_feature LeftArea))
{
MoveWindow(pos() m_RecoverPosition);
}
else if (frameRect.left() == m_RecoverPosition.x() + (curWidth - HIDE_BORDER)
&& TEST_BIT(m_feature RightArea))
{
MoveWindow(pos() m_RecoverPosition);
}
else if (frameRect.top() == m_RecoverPosition
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-10-02 09:27 deskdockwidget\
文件 5271 2016-10-01 17:37 deskdockwidget\deskdockwidget.cpp
文件 1212 2016-10-01 17:03 deskdockwidget\deskdockwidget.h
文件 91 2011-11-04 15:43 deskdockwidget\deskdockwidget.qrc
文件 973 2016-08-01 14:37 deskdockwidget\deskdockwidget.sln
文件 825 2013-01-10 21:00 deskdockwidget\deskdockwidget.ui
文件 9463 2013-01-10 21:02 deskdockwidget\deskdockwidget.vcproj
文件 10036 2016-10-01 16:22 deskdockwidget\deskdockwidget.vcxproj
文件 2408 2016-10-01 16:22 deskdockwidget\deskdockwidget.vcxproj.filters
目录 0 2016-10-02 09:27 deskdockwidget\images\
文件 15324 2011-10-23 15:56 deskdockwidget\images\m.png
文件 5120 2013-01-10 20:48 deskdockwidget\images\Thumbs.db
文件 206 2016-08-01 15:39 deskdockwidget\main.cpp
文件 332 2016-08-01 14:39 deskdockwidget\qtinclude.h
目录 0 2013-01-10 21:00 deskdockwidget\Resources\
- 上一篇:Qt之QComboBox定制二
- 下一篇:Qt之自定义检索框
评论
共有 条评论