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. [SOLVED] Renaming a tab by double click and then setting Main Window title to new name
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Renaming a tab by double click and then setting Main Window title to new name

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.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.
  • A Offline
    A Offline
    adam0982
    wrote on last edited by
    #1

    Hey everyone,

    I am working on a program where I have a class MainWindow that is derived from QMainWindow. In that class, I initialize mTabWidget = new QTabWidget, then I set this as my central widget (setCentralWidget(mTabWidget). Then to add a tab I use mTabWidget->addTab(scrollArea, fileName), where scrollArea is a QScrollArea pointer and fileName is a QString. Then I set the title of the main window using setWindowTitle(fileName).

    Now my goal is to be able to double click on a tab to rename it. I’ve read that I need to subclass the QTabBar class as well as the QTabWidget to do this. I have this working, but can anyone give me an example on how they would do this or an alternate idea.

    The second part of my problem is that when I double click the tab to rename, I can get it to rename the tab but not set the window title to the new tab name. In my subclass I used the setWindowTitle() method again, but it does nothing.

    I am stumped on this issue and any help would be extremely appreciated.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      This "thread":http://qt-project.org/forums/viewthread/10390 might help you to get started

      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
      • A Offline
        A Offline
        adam0982
        wrote on last edited by
        #3

        Thanks SGaist! I implemented my own TabWidget class derived from QTabWidget so I can access the TabBar() member in order to access the double click event of the TabBar. What's really got me puzzled is how to call the setWindowTitle() method of the MainWindow class that the TabWidget object is initialized in. I need the main window title to match the current tab name. Is there some sort of way to monitor if there is a tab rename?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Add a signal to your custom QTabWidget e.g. tabTitleChanged(const QString& newTitle) and emit it once you finished the editing part.

          You can then connect it to setWindowTitle

          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
          • A Offline
            A Offline
            adam0982
            wrote on last edited by
            #5

            That worked perfectly. Thanks so much brother! Take care.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              Since you have it all working now, please update the thread title prepending [solved] 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

              • Login

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