Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I update the title text on a QDockWidget from within retranslateUi()?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 5.1k Views 1 Watching
  • 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 Offline
    E Offline
    eos pengwern
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • SGaistS SGaist

        Hi,

        It's setWindowTitle

        E Offline
        E Offline
        eos pengwern
        wrote on last edited by eos pengwern
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • Q qt-public-name referenced this topic on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved