Results 1 to 4 of 4

Thread: HELP! problem of QMenu position when i maximize the window

  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default HELP! problem of QMenu position when i maximize the window

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: HELP! problem of QMenu position when i maximize the window

    Instead of the loop, use QWidget::mapToGlobal()

    Quote Originally Posted by yuzhouzhiwai View Post
    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,
    _

  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: HELP! problem of QMenu position when i maximize the window

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: HELP! problem of QMenu position when i maximize the window

    Maybe a difference between geometry() and frameGeometry() in the maximized case, etc.

    Cheers,
    _

Similar Threads

  1. Maximize Window in Background
    By qtoptus in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2012, 14:28
  2. maximize grid with maximize window
    By bibhukalyana in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2011, 08:16
  3. Defining position for QMenu used by QPushButton
    By Ghaleon in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2009, 09:23
  4. Maximize Window button of Manin Window
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 08:20
  5. Maximize Window Signal
    By ToddAtWSU in forum Qt Programming
    Replies: 9
    Last Post: 8th May 2006, 20:05

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.