Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    2
    4
    4030
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      eos pengwern last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        It's setWindowTitle

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        E 1 Reply Last reply Reply Quote 1
        • E
          eos pengwern @SGaist last edited by eos pengwern

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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • Referenced by  Q qt-public-name 
            • First post
              Last post