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
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