Results 1 to 6 of 6

Thread: How to display the same widget in all tabs of a QTabWidget

  1. #1
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How to display the same widget in all tabs of a QTabWidget

    Hello,

    I need to display the same widget (really, the same instance of a widget) in all tabs of a QTabWidget. The idea is that I would change the content of this "shared" widget, based on the selected tab. I cannot instantiate this widget multiple times.

    Is there a clean way to do this?

    I considered the following options:

    - Add the shared widget as a child to all tabs of the QTabWidget. I didn't pursue the idea, because from what I could gather, a widget can have only one parent.

    - Use a QStackedWidget, put the shared widget on the first page, put the QTabWidget on the second page, and somehow make that second page transparent. I can foresee focus problems, though.

    Any idea?

    Cheers,
    Franz

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display the same widget in all tabs of a QTabWidget

    There is no clean way to do this. And I would really advise against any hackish ways of doing that. Why can't you instantiate the same widget class multiple times?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2009
    Posts
    49
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display the same widget in all tabs of a QTabWidget

    Hey, thanks for the reply.

    I was kind of expecting this to not be feasible cleanly, to be honest

    I think letting the user switch the content of a widget using tabs makes sense semantically, but I understand it's preferable not to work around the framework.

    Cheers,
    Franz

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display the same widget in all tabs of a QTabWidget

    You can have tabs without a tab widget, that's not a big problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to display the same widget in all tabs of a QTabWidget

    I have successfully done this by making the TabWidget (not the Tabs) the parent of a Label which has no background.

    I then put a Layout onto the Label, and put various widgets into the label's layout. The widgets in the (invisible) Label layout then appear on all Tabs, and the Tab contents float beneath the Label's widgets.

    I needed to shift the position of the Label away from (0, 0) to avoid the Tab buttons, but that wasn't a problem with move().

    You need to make sure the label does not lie over anything you might want to click on in the Tabs - because it lets you see them, but not click them !

    I usually work in code, but tried this out in Designer first - didn't take long.

    I am now trying to put another invisible Label at the bottom of the TabWidget, but am having difficulty getting an accurate value for height(), since this is not the same during coding as it is at runtime! I guess I will have to use resize events etc for this.

    Hope this is of some use!

  6. #6
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display the same widget in all tabs of a QTabWidget

    Quote Originally Posted by dictoon View Post
    I need to display the same widget (really, the same instance of a widget) in all tabs of a QTabWidget. The idea is that I would change the content of this "shared" widget, based on the selected tab. I cannot instantiate this widget multiple times.

    Is there a clean way to do this?
    Use a QTabBar instead of a QTabWidget.

Similar Threads

  1. Changing names of QTabWidget tabs
    By RThaden in forum Qt Programming
    Replies: 7
    Last Post: 29th January 2019, 22:25
  2. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 13:20
  3. Replies: 7
    Last Post: 8th April 2009, 09:42
  4. QTabWidget - Add Tabs dynamically
    By fruzzo in forum Qt Programming
    Replies: 11
    Last Post: 27th February 2008, 09:26
  5. Switching off all tabs in QTabWidget
    By Gopala Krishna in forum Qt Programming
    Replies: 7
    Last Post: 30th August 2006, 18:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.