Results 1 to 2 of 2

Thread: QTabbar with rich text / html tab text

  1. #1
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QTabbar with rich text / html tab text

    Does anybody have experience with getting the Tabs in a QTabbar to render html/rich text?
    I couldn't find any references on the web for this and could use a push in the right direction.

    Thank you

  2. #2
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QTabbar with rich text / html tab text

    Ok I couldn't find an ideal solution to this problem, so I implemented a quick and dirty one that I thought I would share.

    QTabbar actually supports having two widgets on each tab, one on the right, and one on the left ( this is how close buttons are made ), so instead of setting the text on the tabs I write the text to a label (which supports html) and force it to take up the width of the whole tab.

    Qt Code:
    1. class RichTextTabBar : public QTabBar
    2. {
    3. Q_OBJECT
    4. public:
    5. void setTabText(int index, const QString& text)
    6. {
    7. QLabel* label = new QLabel(text);
    8. label->setFixedSize(mTabWidth, mTabHeight);
    9. label->setStyleSheet("padding-top:0px; padding-bottom:0px; padding-left:5px; padding-right:5px;");
    10. setTabButton(index, QTabBar::LeftSide, label);
    11. }
    12.  
    13. private:
    14. int mTabWidth;
    15. int mTabHeight;
    16. };
    17.  
    18. class RichTextTabWidget : public QTabWidget
    19. {
    20. Q_OBJECT
    21. public:
    22. RichTextTabWidget(QWidget* parent = 0)
    23. : QTabWidget(parent)
    24. {
    25. setTabBar(new RichTextTabBar());
    26. }
    27.  
    28. void setTabText(int index, const QString &label)
    29. {
    30. tabBar()->setTabText(index, label);
    31. }
    32.  
    33. private:
    34. RichTextTabBar* tabBar() const;
    35. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 6th December 2011, 22:44
  2. how to use html tags(rich text) in QTableWidgetHeaderItem
    By ansmehta in forum Qt Programming
    Replies: 0
    Last Post: 13th December 2010, 10:20
  3. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  4. QWidget pixmap AFTER displaying html ("rich text")
    By gavrilo princep in forum Newbie
    Replies: 0
    Last Post: 17th July 2007, 01:59

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.