Results 1 to 3 of 3

Thread: Mouse Translation

  1. #1
    Join Date
    Jan 2010
    Location
    Dhaka, Bangladesh
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Mouse Translation

    Hi ....
    I am adding QgraphicsItem in scene and it works fine in the application... but when i change mouse position to switch another application in taskbar then crashes....
    but i dont understand why & from where the problem is happening...

    here is debug tracer....

    0 QApplicationPrivate::notify_helper qapplication.cpp 4396 0x01d396f5
    1 QApplication::notify qapplication.cpp 3798 0x01d37012
    2 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    3 QCoreApplication::sendEvent qcoreapplication.h 215 0x023ad592
    4 QGraphicsScenePrivate::sendEvent qgraphicsscene.cpp 1207 0x022d525f
    5 QGraphicsScene::sendEvent qgraphicsscene.cpp 5673 0x022e3a3b
    6 QGraphicsItem::sceneEvent qgraphicsitem.cpp 6718 0x022b9eae
    7 QGraphicsScenePrivate::sendEvent qgraphicsscene.cpp 1211 0x022d5297
    8 QGraphicsScene::sendEvent qgraphicsscene.cpp 5673 0x022e3a3b
    9 QGraphicsScene::event qgraphicsscene.cpp 3508 0x022dbdbe
    10 QApplicationPrivate::notify_helper qapplication.cpp 4396 0x01d39706
    11 QApplication::notify qapplication.cpp 3798 0x01d37012
    12 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    13 QCoreApplication::sendEvent qcoreapplication.h 215 0x023ad592
    14 QGraphicsView::viewportEvent qgraphicsview.cpp 2765 0x022fa541
    15 QAbstractScrollAreaPrivate::viewportEvent qabstractscrollarea_p.h 100 0x023e6a13
    16 QAbstractScrollAreaFilter::eventFilter qabstractscrollarea_p.h 116 0x023e506c
    17 QCoreApplicationPrivate::sendThroughObjectEventFil ters qcoreapplication.cpp 847 0x6a1ffc73
    18 QApplicationPrivate::notify_helper qapplication.cpp 4392 0x01d396e5
    19 QApplication::notify qapplication.cpp 4361 0x01d39586
    20 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    21 QCoreApplication::sendEvent qcoreapplication.h 215 0x023ad592
    22 QWidget::event qwidget.cpp 8443 0x01d84ce8
    23 QFrame::event qframe.cpp 557 0x020fe6bc
    24 QAbstractScrollArea::event qabstractscrollarea.cpp 996 0x0218be88
    25 QGraphicsView::event qgraphicsview.cpp 2739 0x022fa37b
    26 QApplicationPrivate::notify_helper qapplication.cpp 4396 0x01d39706
    27 QApplication::notify qapplication.cpp 4361 0x01d39586
    28 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    29 QCoreApplication::sendEvent qcoreapplication.h 215 0x023ad592
    30 QWidget::event qwidget.cpp 8443 0x01d84ce8
    31 QGroupBox::event qgroupbox.cpp 397 0x020ff5fe
    32 QApplicationPrivate::notify_helper qapplication.cpp 4396 0x01d39706
    33 QApplication::notify qapplication.cpp 4361 0x01d39586
    34 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    35 QCoreApplication::sendEvent qcoreapplication.h 215 0x023ad592
    36 QWidget::event qwidget.cpp 8443 0x01d84ce8
    37 QMainWindow::event qmainwindow.cpp 1417 0x0211d23a
    38 QApplicationPrivate::notify_helper qapplication.cpp 4396 0x01d39706
    39 QApplication::notify qapplication.cpp 4361 0x01d39586
    40 QCoreApplication::notifyInternal qcoreapplication.cpp 732 0x6a1ff9dc
    41 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 218 0x023ad53e
    42 QApplication::setActiveWindow qapplication.cpp 2549 0x01d34956
    43 QtWndProc@16 qapplication_win.cpp 1993 0x01d9bba0
    44 USER32!GetDC C:\WINDOWS\system32\user32.dll 0 0x7e418734
    45 USER32!GetDC C:\WINDOWS\system32\user32.dll 0 0x7e418734
    46 ?? 0 0x001702ca
    47 ?? qwidget.h 487 0x0000001c
    48 USER32!GetDC C:\WINDOWS\system32\user32.dll 0 0x7e418816
    49 qt_is_translatable_mouse_event qapplication_win.cpp 1426 0x01d99fa5
    50 USER32!DefWindowProcW C:\WINDOWS\system32\user32.dll 0 0x7e428ea0
    51 ?? 0 0x00000000

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Mouse Translation

    null pointer?

    Post some code.

  3. #3
    Join Date
    Jan 2010
    Location
    Dhaka, Bangladesh
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Mouse Translation

    hi squidge....

    here is my code please check it......



    #include "myGraphicsItemLinear.h"
    #include "myGraphicsItemLine.h"
    #include "myGraphicsItemPropertyFactory.h"

    myGraphicsItemLinear::myGraphicsItemLinear(int nToolID)
    {
    m_bReshapeable = true;
    setItemID(nToolID);

    m_Pen1 = NULL;
    m_Pen2 = NULL;
    m_Pen3 = NULL;
    m_Pen4 = NULL;
    m_Pen5 = NULL;
    }

    myGraphicsItem* myGraphicsItemLinear::clone()
    {
    myGraphicsItem *pItemSelf = new myGraphicsItemLinear(m_nItemID);
    pItemSelf->setItemName(m_strItemName);
    pItemSelf->loadImage();
    pItemSelf->setZValue(this->zValue());
    pItemSelf->setMeterPerPixel(m_fMeterPerPixel);
    pItemSelf->setPolygon(this->polygon());
    pItemSelf->setItemProperty(this->m_pItemProperty->clone());
    pItemSelf->setFlags(flags());
    //
    return pItemSelf;
    }

    QRectF myGraphicsItemLinear::boundingRect() const
    {
    QRectF rect(QGraphicsPolygonItem::boundingRect());

    if(m_Pen1 != NULL)
    {
    qreal deviation = m_Pen1->widthF();
    rect.adjust(-deviation, -deviation, deviation, deviation);
    return rect;
    }
    else
    {
    return rect.adjusted(-1,-1,1,1);
    }
    }

    void myGraphicsItemLinear:ropertyChanged(QStandardItem *item)
    {
    setToolTipFromProperty();
    }

    void myGraphicsItemLinear:aint(QPainter *painter,
    const QStyleOptionGraphicsItem *option,
    QWidget *widget)
    {
    //
    painter->setRenderHint(QPainter::Antialiasing);

    if(m_Pen1 != NULL)
    {
    QColor colorPre(m_Pen1->color());
    if(isSelected())
    {
    m_Pen1->setColor(Qt::red);
    }
    painter->setPen(*m_Pen1);
    painter->drawPolyline(m_itemPolygon);
    m_Pen1->setColor(colorPre);
    }
    if(m_Pen2 != NULL)
    {
    painter->setPen(*m_Pen2);
    painter->drawPolyline(m_itemPolygon);
    }
    if(m_Pen3 != NULL)
    {
    painter->setPen(*m_Pen3);
    painter->drawPolyline(m_itemPolygon);
    }
    if(m_Pen4 != NULL)
    {
    painter->setPen(*m_Pen4);
    painter->drawPolyline(m_itemPolygon);
    }
    if(m_Pen5 != NULL)
    {
    painter->setPen(*m_Pen5);
    painter->drawPolyline(m_PolygonInternationalDemarcated);
    }
    }

    QPolygonF myGraphicsItemLinear:olygon() const
    {
    return m_itemPolygon;
    }

    void myGraphicsItemLinear::setPolygon(const QPolygonF &polygon)
    {
    bool rePos = false;
    if(m_itemPolygon.count() == polygon.count())
    {
    rePos = true;
    }
    m_itemPolygon = polygon;
    //
    QVector<QPointF> revVect;
    QPolygonF tmpPoly(polygon);
    QPointF ptNext(0,0);
    bool bNextPoint = true;

    for(int i=m_itemPolygon.count()-1; i>-1; i--)
    {
    revVect.append(m_itemPolygon.at(i));

    QPointF pt = m_itemPolygon.at(i);
    // pt.setY(pt.y()+ 2.5);
    // m_PolygonInternationalDemarcated.append(pt);

    if (bNextPoint )
    {
    ptNext = pt;
    bNextPoint = false;
    QPointF pt = m_itemPolygon.at(i - 1);

    int nX = qAbs(pt.x() - ptNext.x());
    int nY = qAbs(pt.y() - ptNext.y());

    if (nX > nY)
    {
    ptNext.setY(ptNext.y()+ 2.5);
    m_PolygonInternationalDemarcated.append(ptNext);
    }
    else if (nX < nY)
    {
    ptNext.setX(ptNext.x() + 2.5);
    m_PolygonInternationalDemarcated.append(ptNext);
    }
    }
    else
    {
    int nX = qAbs(pt.x() - ptNext.x());
    int nY = qAbs(pt.y() - ptNext.y());

    if (nX > nY)
    {
    pt.setY(pt.y()+ 2.5);
    m_PolygonInternationalDemarcated.append(pt);
    }
    else if (nX < nY)
    {
    pt.setX(pt.x() + 2.5);
    m_PolygonInternationalDemarcated.append(pt);
    }

    if (pt.x() != ptNext.x() || pt.y() != ptNext.y())
    {
    ptNext = pt;
    }
    } //
    }

    tmpPoly += revVect;

    QGraphicsPolygonItem::setPolygon(tmpPoly);
    //
    if(rePos)
    {
    repositionSegmentItem(polygon);
    }
    else
    {
    createSegmentItem(polygon);
    }
    }

    void myGraphicsItemLinear::setMeterPerPixel(const float& fMeter)
    {
    m_fMeterPerPixel = fMeter;
    loadImage();
    }

    void myGraphicsItemLinear::createSegmentItem(const QPolygonF &polygon)
    {
    qDebug("myGraphicsItemLinear::createSegmentItem");
    int nChildID = 1110;


    QPolygonF poly;
    myGraphicsItemLine *pSegment = NULL;
    int i;
    for(i = 0; i < polygon.count()-1; i++)
    {
    poly << polygon.at(i) << polygon.at(i+1);
    pSegment = new myGraphicsItemLine(nChildID, this);
    pSegment->setPolygon(poly);
    //
    pSegment->setFlag(ItemIsSelectable, true);
    pSegment->setFlag(ItemIsMovable, false);
    pSegment->setFlag(ItemIsFocusable, false);
    //
    poly.clear();
    }
    }

    void myGraphicsItemLinear::repositionSegmentItem(const QPolygonF &polygon)
    {
    //qDebug("myGraphicsItemLinear::repositionSegmentIte m");
    QPolygonF poly;
    myGraphicsItemLine *pSegment = NULL;

    int i;
    for(i = 0; i < polygon.count()-1; i++)
    {
    poly << polygon.at(i) << polygon.at(i+1);
    pSegment = (myGraphicsItemLine*)childItems().at(i);
    pSegment->setPolygon(poly);
    pSegment->update();
    //
    poly.clear();
    }
    }

    void myGraphicsItemLinear::setItemProperty(myGraphicsIt emProperty* pProperty)
    {
    //
    myGraphicsItem::setItemProperty(pProperty);

    //
    myGraphicsItemLine *pSegment = NULL;
    myGraphicsItemProperty *pSegmentProperty;
    QStandardItemModel *pModel = pProperty->getStandardModel();
    int i,j;
    for(i = 0; i< childItems().count(); i++)
    {
    pSegmentProperty = new myGraphicsItemProperty(m_nItemID);
    //
    for(j = 0; j< pModel->rowCount(); j++)
    {
    pSegmentProperty->addProperty(pModel->item(j, 0)->text(), pModel->item(j, 1)->text());
    }
    pSegmentProperty->setSegmentID(i);
    //
    pSegment = (myGraphicsItemLine*)childItems().at(i);
    if(pSegment)
    {
    pSegment->setItemProperty(pSegmentProperty);
    }
    }
    }


    void myGraphicsItemLinear::loadImage()
    {

    switch(m_nItemID)
    {
    case ID_TOOL_TERRAIN_RAILWAYS_BROADGAUGE_DOUBLE:
    {
    m_Pen1 = new QPen();
    m_Pen2 = new QPen();

    m_Pen1->setStyle(Qt::SolidLine);
    m_Pen1->setColor(Qt::black);
    m_Pen1->setWidthF(3/m_fMeterPerPixel);
    //
    QVector<qreal> pattern;
    pattern.append(qreal(3));
    pattern.append(qreal(11));
    m_Pen2->setDashPattern(pattern);
    m_Pen2->setDashOffset(4);
    m_Pen2->setColor(Qt::white);
    m_Pen2->setWidthF(2/m_fMeterPerPixel);
    }break;

    case ID_TOOL_TERRAIN_RAILWAY_MIXED_GAUGE:
    {
    m_Pen1 = new QPen();
    m_Pen2 = new QPen();

    m_Pen1->setStyle(Qt::SolidLine);
    m_Pen1->setColor(Qt::black);
    m_Pen1->setWidthF(3/m_fMeterPerPixel);
    //
    QVector<qreal> pattern;
    pattern.append(qreal(3));
    pattern.append(qreal(11));
    m_Pen2->setDashPattern(pattern);
    m_Pen2->setDashOffset(4);
    m_Pen2->setColor(Qt::white);
    m_Pen2->setWidthF(2/m_fMeterPerPixel);

    pattern[0] = qreal(10);
    pattern[1] = qreal(4);

    m_Pen3 = new QPen();

    m_Pen3->setStyle(Qt::SolidLine);
    m_Pen3->setColor(Qt::black);
    m_Pen3->setWidthF(.5/m_fMeterPerPixel);
    }break;

    default:
    {
    m_Pen1 = NULL;
    m_Pen2 = NULL;
    m_Pen3 = NULL;
    m_Pen4 = NULL;
    m_Pen5 = NULL;
    }break;
    };
    }

Similar Threads

  1. UI translation
    By Annihilator in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2010, 11:37
  2. translation
    By weixj2003ld in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2010, 01:01
  3. Problrm with Qt translation
    By chandan in forum Qt Tools
    Replies: 1
    Last Post: 23rd May 2010, 20:21
  4. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 11:01
  5. Translation
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 17:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.