• 4085阅读
  • 0回复

求助:qt实现TabWidget标签拖动生成新窗口,程序崩溃 [复制链接]

上一主题 下一主题
离线aaaa163hf
 

只看楼主 倒序阅读 楼主  发表于: 2016-07-08
— 本帖被 toby520 从 Qt 作品展 移动到本区(2016-07-11) —
程序运行示例如下:



关键代码:
bool myTabWidget::eventFilter(QObject *o, QEvent *e)
{
    if(o==m_pTabBar)
    {
        if(e->type()==QEvent::MouseButtonPress)
        {
            QMouseEvent *me=static_cast<QMouseEvent *>(e);
            if(me->buttons()&Qt::LeftButton)
            {
                cpoint=me->pos();
            }
        }
        if(e->type()==QEvent::MouseMove)
        {
            QMouseEvent *me=static_cast<QMouseEvent *>(e);
            if(me->buttons()&Qt::LeftButton)
            {
                int index=m_pTabBar->currentIndex();
                if((me->y()<m_pTabBar->y()) || me->y()>(m_pTabBar->y()+m_pTabBar->height()))
                {
                    starDrag(index,me);
                    return true;
                }
            }
        }
    }


    return QTabWidget::eventFilter(o,e);
}TabWidget设成setMovable(false)拖动最后一个标签是没问题的,但是设成setMovable(true)就会拖动最后一个标签出现程序崩溃情况。错误提示如下:QPixmap::grabWidget is deprecated, use QWidget::grab() instead
ASSERT failure in QList<T>::operator[]: "index out of range", file ..\..\include/QtCore/../../src/corelib/tools/qlist.h, line 539
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
快速回复
限100 字节
 
上一个 下一个