Qt World Summit: Submit your Presentation

GUI/Dialog refreshing - where to begin?

  • Newbie Qt question here.

    I'm retrofitting internationalization into a piece of 3rd party software my employer has purchased for integration into our product. The internationalization itself has gone well, but I'm having a problem with refresh of its main menu, a QDialog subclass which floats at top centre of its QMainWindow subclass main window. The code handling the internationalization resides in the main window where, when its retranslateUi() method is fired, a retranslateMenu() method is fired in another, pre-existing "dialog manager" class. This calls setTitle on each QMenu title and _setText _on each menu item QAction to refresh translated texts.

    At the end of retranslateMenu() a recalculate() method belonging to the menu dialog is called,
    @void MenuDialog::recalculate()
    // QWidget main widget delegated for the dialog

    // QMenuBar providing the menu itself.
    // Enforce centering of the main menu dialog / bar when menu width changes.
    QRect windowGeometry = m_parent->geometry();
    QPoint position = QPoint((m_parent->geometry().width() - width()) / 2, 50);


    The recomputeSize() method called is from a parent class, PanelDialog, and reads as follows:
    @void PanelDialog::recomputeSize()
    setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));

    This seems to work fine as far as it goes. When I trigger a language change from English to (longer) French menu titles, both the menu bar and the dialog main widget containing it resize correctly, based on the sizeHint() value increasing from about 400 to, at present, a deliberately exaggerated 800 pixels.

    Problem is that the first time I do this, the dialog does not fully repaint. It resizes and re-centres, but only as much of it as was originally originally painted (400 pixels) is shown. Hovering the mouse over the menu bar will cause individual QMenu items to be repainted, but not the dialog widget, so I get a weird effect of the menu floating with no dialog under it--however, if I do a single left-mouse-click anywhere on the main window itself, the whole dialog is repainted correctly.

    This defect only applies for the first transition from shorter to longer menu bar. After that, I can go back and forth as long as I like, and all is well.

    Where can I go to learn how to make either the menu dialog or the window repaint fully on that first transition? I've tried repaint() and update() calls, with and without qApp->processEvents() and...no luck so far. Obviously missing something, or have not yet found the right references to study.

Log in to reply