Results 1 to 2 of 2

Thread: Replacing icons of tabs QTabWidget with labels on customwidget

  1. #1
    Join Date
    Jul 2011
    Posts
    31
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Replacing icons of tabs QTabWidget with labels on customwidget

    Hi,

    I was looking for a way to replace the icon on the tab of a tabbed widget with a Qlabel so I can play a movie on it. I tried using settabbutton with a qlabel but it just resizes the label and puts it on the side of the icon. I would like to totally replace the icon with the label if possible and set the same size as the icon for the label. This is a standalone widget.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Replacing icons of tabs QTabWidget with labels on customwidget

    By default QTabWidget tab's don't have icons, you might have added it, just avoid adding it.

    You can sub-class QTabWidget and implement the below virtual method, it will set the QLabel on to the tab of the newly added tab page(widget)

    Qt Code:
    1. void myTabWidget::tabInserted(int index)
    2. {
    3. QString text = tabText(index);
    4. setTabText(index, QString()); //clear the title in the tab, if you want
    5.  
    6. QLabel * label = new QLabel(text);
    7. label->setFont(QFont("Arial", 48, 100, true));
    8. tabBar()->setTabButton(index, QTabBar::LeftSide, label);
    9. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 12:20
  2. Adding tabs in a QTabWidget
    By Hogwarts in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2011, 19:40
  3. Qt Designer How to set a QTabWidget with two rows of tabs?
    By lmfgy123 in forum Qt Tools
    Replies: 1
    Last Post: 17th November 2010, 06:49
  4. Qtabwidget - how to add a button to all tabs?
    By creep33 in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2010, 19:05
  5. QTabWidget - Add Tabs dynamically
    By fruzzo in forum Qt Programming
    Replies: 11
    Last Post: 27th February 2008, 08:26

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.