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.
class RichTextTabBar
: public QTabBar{
Q_OBJECT
public:
void setTabText(int index, const QString& text)
{
label->setFixedSize(mTabWidth, mTabHeight);
label->setStyleSheet("padding-top:0px; padding-bottom:0px; padding-left:5px; padding-right:5px;");
setTabButton
(index,
QTabBar::LeftSide, label
);
}
private:
int mTabWidth;
int mTabHeight;
};
{
Q_OBJECT
public:
RichTextTabWidget
(QWidget* parent
= 0) {
setTabBar(new RichTextTabBar());
}
void setTabText
(int index,
const QString &label
) {
tabBar()->setTabText(index, label);
}
private:
RichTextTabBar* tabBar() const;
};
class RichTextTabBar : public QTabBar
{
Q_OBJECT
public:
void setTabText(int index, const QString& text)
{
QLabel* label = new QLabel(text);
label->setFixedSize(mTabWidth, mTabHeight);
label->setStyleSheet("padding-top:0px; padding-bottom:0px; padding-left:5px; padding-right:5px;");
setTabButton(index, QTabBar::LeftSide, label);
}
private:
int mTabWidth;
int mTabHeight;
};
class RichTextTabWidget : public QTabWidget
{
Q_OBJECT
public:
RichTextTabWidget(QWidget* parent = 0)
: QTabWidget(parent)
{
setTabBar(new RichTextTabBar());
}
void setTabText(int index, const QString &label)
{
tabBar()->setTabText(index, label);
}
private:
RichTextTabBar* tabBar() const;
};
To copy to clipboard, switch view to plain text mode
Bookmarks