Important: Please read the Qt Code of Conduct -

How do I update the title text on a QDockWidget from within retranslateUi()?

  • When I create a new QDockWidget, I can set its title text in the currently-selected language thus:

    QDockWidget *myDockWidget = new QDockWidget(tr("This is my cool dock widget"), this);

    However, if the user subsequently selects a different language for the application interface, I'd like to be able to do something like the following from my QMainWindow's retranslateUi() method:

    myDockWidget -> setTitle(tr("This is my cool dock widget"));

    However, no such method seems to exist in QDockWidget. It seems that the title bar is actually implemented as some anonymous widget of its own,and althogh I can obtain a pointer to it using QDockWidget::titleBarWidget(), this just returns a pointer to a QWidget base class; it doesn't have a virtual setText method that I could invoke, and because I don't know what the titleBarWidget actually is I can't do a static cast to it.

    So, is there really no way to change the title of a QDockWidget after it has been constructed? Must my retranslated GUI still have the window bar titles in the original language when everything else around them is translated? The only workaround I can think of so far is to create a custom title bar widget all of my own and make sure that it has a setText() method, but I doubt I'd be able to create the same native look-and-feel of the default version.

  • Lifetime Qt Champion


    It's setWindowTitle

  • @SGaist Aha, I should have know it would be something obvious, if only I'd known where to look! Thank you.

  • Lifetime Qt Champion

    Use the doc Luke ;)

    Since it's all good now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)

Log in to reply