public:
int countFlag(QPoint p, int row);
void setCursorType(int flag);
int countRow(QPoint p);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void mouseDoubleClickEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
bool _isleftpressed;
int _curpos;
QPoint _plast;
//構(gòu)造this->setMouseTracking(true);
_isleftpressed= false;
_curpos= 0;//標(biāo)記鼠標(biāo)左擊時(shí)的位置this->setMinimumSize(600, 400);//設(shè)置最小尺寸
void my_window::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
this->_isleftpressed = true;
QPoint temp= event->globalPos();
_plast= temp;
_curpos= countFlag(event->pos(), countRow(event->pos()));
event->ignore();
}
}
void my_window::mouseReleaseEvent(QMouseEvent *event)
{
if (_isleftpressed)
_isleftpressed= false;
setCursor(Qt::ArrowCursor);
event->ignore();
}
void my_window::mouseDoubleClickEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
if (windowState() != Qt::WindowFullScreen)
setWindowState(Qt::WindowFullScreen);
else setWindowState(Qt::WindowNoState);//恢復(fù)正常模式 }
event->ignore();
}
void my_window::mouseMoveEvent(QMouseEvent *event)//鼠標(biāo)移動(dòng)事件 {
int poss = countFlag(event->pos(), countRow(event->pos()));
setCursorType(poss);
if (_isleftpressed)//是否左擊 {
QPoint ptemp= event->globalPos();
ptemp= ptemp - _plast;
if (_curpos == 22)//移動(dòng)窗口 {
ptemp= ptemp + pos();
move(ptemp);
}
else
{
QRect wid= geometry();
switch (_curpos)//改變窗口的大小 {
case 11:wid.setTopLeft(wid.topLeft() + ptemp); break;//左上角 case 13:wid.setTopRight(wid.topRight() + ptemp); break;//右上角 case 31:wid.setBottomLeft(wid.bottomLeft() + ptemp); break;//左下角 case 33:wid.setBottomRight(wid.bottomRight() + ptemp); break;//右下角 case 12:wid.setTop(wid.top() + ptemp.y()); break;//中上角 case 21:wid.setLeft(wid.left() + ptemp.x()); break;//中左角 case 23:wid.setRight(wid.right() + ptemp.x()); break;//中右角 case 32:wid.setBottom(wid.bottom() + ptemp.y()); break;//中下角 }
setGeometry(wid);
}
_plast= event->globalPos();//更新位置 }
event->ignore();
}
int my_window::countFlag(QPoint p, int row)//計(jì)算鼠標(biāo)在哪一列和哪一行 {
if (p.y()<MARGIN)
return 10 + row;
else if (p.y()>this->height() - MARGIN)
return 30 + row;
else return 20 + row;
}
void my_window::setCursorType(int flag)//根據(jù)鼠標(biāo)所在位置改變鼠標(biāo)指針形狀 {
Qt::CursorShape cursor;
switch (flag)
{
case 11:
case 33:
cursor= Qt::SizeFDiagCursor; break;
case 13:
case 31:
cursor= Qt::SizeBDiagCursor; break;
case 21:
case 23:
cursor= Qt::SizeHorCursor; break;
case 12:
case 32:
cursor= Qt::SizeVerCursor; break;
case 22:
//cursor = Qt::OpenHandCursor; break; cursor = Qt::ArrowCursor; break;
default:
cursor= Qt::ArrowCursor; break;
break;
}
setCursor(cursor);
}
int my_window::countRow(QPoint p)//計(jì)算在哪一列 {
return (p.x()<MARGIN) ? 1 : (p.x()>(this->width() - MARGIN) ? 3 : 2);
}
網(wǎng)站設(shè)計(jì)制作過程拒絕使用模板建站;使用PHP+MYSQL原生開發(fā)可交付網(wǎng)站源代碼;符合網(wǎng)站優(yōu)化排名的后臺(tái)管理系統(tǒng);成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)收費(fèi)合理;免費(fèi)進(jìn)行網(wǎng)站備案等企業(yè)網(wǎng)站建設(shè)一條龍服務(wù).我們是一家持續(xù)穩(wěn)定運(yùn)營(yíng)了十載的創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司。
網(wǎng)站題目:QT_無邊框窗口拖動(dòng)縮放-創(chuàng)新互聯(lián)
新聞來源:http://jinyejixie.com/article16/djsgdg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站改版、自適應(yīng)網(wǎng)站、外貿(mào)建站、ChatGPT、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容