• 3972阅读
  • 3回复

窗口拖拽问题 [复制链接]

上一主题 下一主题
离线banyibanyi
 

只看楼主 倒序阅读 楼主  发表于: 2010-03-03
我的一个窗口用了去标题栏的风格 所以无法拖动
我希望能够拖动,应该如何实现,希望大家给点思路,方法 谢谢
离线banyibanyi

只看该作者 1楼 发表于: 2010-03-04
大家帮忙看看哦
离线google
只看该作者 2楼 发表于: 2010-04-08
//last 和pos0是myForm的私有变量
//mainFrame是你要让他有拖动效果的组件
void myForm::mouseMoveEvent(QMouseEvent *e)
{
    //处理整个范围内的事件,可以自己更改范围
    QPoint temp = e->pos();
    const int pos_min_x = ui.mainFrame->pos().x();
    const int pos_max_x = pos_min_x + ui.mainFrame->width();
    const int pos_min_y = ui.mainFrame->pos().y();
    const int pos_max_y = pos_min_y + ui.mainFrame->height();

    if( (temp.x() > pos_min_x) && (temp.x() < pos_max_x) &&
        (temp.y() > pos_min_y) && (temp.y() < pos_max_y))
    {
        QPoint newpos = e->globalPos();
        QPoint upleft = pos0 + newpos - last;
        this->move(upleft);
    }
}

void myForm::mousePressEvent(QMouseEvent *e)
{
    QPoint temp = e->pos();
    const int pos_min_x = ui.mainFrame->pos().x();
    const int pos_max_x = pos_min_x + ui.mainFrame->width();
    const int pos_min_y = ui.mainFrame->pos().y();
    const int pos_max_y = pos_min_y + ui.mainFrame->height();

    if( (temp.x() > pos_min_x) && (temp.x() < pos_max_x) &&
        (temp.y() > pos_min_y) && (temp.y() < pos_max_y))
    {
        last = e->globalPos();
        pos0 = e->globalPos() -e->pos();
    }
}
离线yangfanxing
只看该作者 3楼 发表于: 2010-04-08
呵~挺好~
PHPWind好恶心。。。不想看这种界面。。。
快速回复
限100 字节
 
上一个 下一个