PDA

View Full Version : coordinate transfrom on Max OS X



yxtx1984
27th November 2010, 03:03
This is some codes in some project under Mac OS X, Qt Version 4.7.1, cocoa.

// pMainWindow is equal to pParent, and it is a subclass of QMainWindow.
// m_pResizeBorder is a widget, I just want to make the topLeft of m_pResizeBorder is
// the same place with myWidget, myWidget is a child of pMainWindow.
void myWidget::matchPos()
{
QWidget* pMainWindow = GetMainWindow();
QWidget* pParent = m_pResizeBorder->parentWidget();

// the value of globalPos2 is (62, 52), because of menuBar and application dock bar
QPoint globalPos2 = pMainWindow->mapToGlobal(QPoint(0, 0));

QPoint globalPos = mapToGlobal(QPoint(0,0));

// topPos is equal to topPos2, the value is (0,0)
QPoint topPos = mapTo(pMainWindow, QPoint(0, 0));
QPoint topPos2 = pMainWindow->mapFromGlobal(mapToGlobal(QPoint(0, 0)));

QRect frame;
frame.setTopLeft(topPos2);
frame.setWidth(rect().width());
frame.setHeight(rect().height());
m_pResizeBorder->setGeometry(frame);
QPoint globalPos3 = m_pResizeBorder->mapToGlobal(QPoint(0, 0));
}

I think the value of globalPos3 is equal to globalPos2, but in fact the value of globalPos3 is (0,0). And if i set topleft of frame to globalPos, globalPos3 is equal to globalPos2. So i think something is wrong, isn't it?