PDA

View Full Version : HELP! problem of QMenu position when i maximize the window



yuzhouzhiwai
12th February 2014, 08:34
Hi!
I designed a new ComboBox inherit from QWidget. when user clicks the new combobox, it will show a QMenu. The position of the QMenu need to be calculated. here is my code:
void CRichComboBox::show()
{
.....
int x= this->pos().x() + 5, y=this->geometry().height() + this->pos().y() ;
QWidget *parent = (QWidget*)this->parent();
while (parent)
{
x += parent->pos().x();
y += parent->pos().y();
parent = (QWidget*)parent->parent();
}

m_pitemsListview->move(x, y);
.......
}
/////////////////////////////////////////////////////////
//m_pitemsListview is a QMenu object ;
// Also I want to ask whether the code above is right for finding the position of QMenu ?
// thank you
////////////////////////////////////////////////////////

when the code running in windows, it works fine. in Linux(Red hat), I click the new combobox, for example, the QMenu show at position (X, Y), then i maximize the window,the QMenu also show at position(X,Y). it seems like when i maximize my widget, its position didn't change.

Thank you

anda_skoa
12th February 2014, 09:07
Instead of the loop, use QWidget::mapToGlobal()


Hi!
when the code running in windows, it works fine. in Linux(Red hat), I click the new combobox, for example, the QMenu show at position (X, Y), then i maximize the window,the QMenu also show at position(X,Y). it seems like when i maximize my widget, its position didn't change.


I am not sure what you mean. You maximize the window and then show the menu again? Or you maximize the window while the menu is showing, recalculate its position but it is not moving?

Cheers,
_

yuzhouzhiwai
13th February 2014, 01:38
thank you for the answer.
I maximize the window and then show the menu again.
and i recalculate its position , but the menu don't move.

when i use the mapToGlobal function , the problem has resolved. Thank you very much.

But I am also confused. what's the problem with my code. whether the widget doesn't update its position timely?


thanks again for you answer.

anda_skoa
13th February 2014, 09:44
Maybe a difference between geometry() and frameGeometry() in the maximized case, etc.

Cheers,
_