MouseEvent中的globalPos()函数返回的是相对屏幕的位置坐标,而pos()则是返回鼠标在当前控件(即捕获该鼠标事件的控件)中的位置 2.核心代码 void MyTitleBar::mousePressEvent(QMouseEvent *e) { int maxWidth = this->width(); int maxHeight = 35; // 鼠标点击的有效高度 可根据实际适当调整 if(e->button...
{ ui->setupUi(this); this->setAttribute(Qt::WA_TranslucentBackground); this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); ui->widget->installEventFilter(this); ui->widget->setStyleSheet(QString("background-image:url(:/image/%1.png);")...
2.3 实现关闭、最大化,最小化,按钮的响应 //顶部按钮响应connect(ui.pBClose, &QPushButton::clicked, [=]() {close(); }); connect(ui.pBMaxWindow,&QPushButton::clicked, [=]() {if(this->isMaximized()) {this->showNormal(); }else{this->showMaximized(); } }); connect(ui.pBMinWindow,...
connect(splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(slotSplitterMoved(int,int))); leftIcon =QIcon(":/left.png"); rightIcon =QIcon(":/right.png"); pushButton =new QPushButton(this); pushButton->setFocusPolicy(Qt::NoFocus); pushButton->hide(); pushButton->setFixedSize(13, 4...
QPoint mainWinPos = this->pos(); this->move(mainWinPos.x() + movePoint.x(), mainWinPos.y() + movePoint.y()); m_StartPoint = curPoint; } } void FuliyePeriod::mouseReleaseEvent(QMouseEvent * event) { m_leftMousePressed = false;//释放鼠标 ...
voidForm::update(){staticint cnt=0;QScreen*screen=QGuiApplication::primaryScreen();QRect rect;rect.setX(this->mapToGlobal(this->pos()).x());rect.setY(this->mapToGlobal(this->pos()).y());rect.setWidth(this->width());rect.setHeight(this->height());screen->grabWindow(0,rect.x()...
offset=event->globalPos()-this->pos(); } } void MainWindow::mouseMoveEvent(QMouseEvent*event){ if(event->buttons()==Qt::LeftButton){//如果鼠标按下的是左键 QPointtmp; tmp=event->globalPos()-offset; move(tmp); } } void MainWindow::mouseReleaseEvent(QMouseEvent*event){...
QtToolBar::QtToolBar(QWidget*parent):QtWidgetBase(parent){m_animation=newQPropertyAnimation(this,"pos");m_animation->setDuration(200);m_animation->setEasingCurve(QEasingCurve::Linear);connect(m_animation,SIGNAL(finished()),this,SIGNAL(signalFinihed()));}voidQtToolBar::SetAnimation(constQPoint...
//设置固定大小this->setFixedSize(320,588);//设置应用图片this->setWindowIcon(QPixmap(":/res/Coin0001.png"));//设置窗口标题this->setWindowTitle("老帮主带你翻金币"); 运行效果如图: 实现点击开始,退出游戏功能,代码如下: 2.设置背景图片 //点击退出,退出程序connect(ui->actionQuit,&QAction::triggere...
this->viewport()->setCursor(Qt::CrossCursor);this->viewport()->update(); 获取子窗口geometry,判断是否包含光标所在的坐标,如果是,则表示光标正悬浮在该子控件上。 注意geometry()是相对于父窗口的相对位置,而QCursor::pos()获取的是鼠标绝对位置。需要进行一次转换,要不将父窗口的相对位置进行换算,要不将鼠...