QTabWidget的tabposition为west时,改变tab文字方向为从上到下

QTabWidget在tabPosition设置为west时,tab的文字方向默认为从下到上


要将tab的文字方向设置为从上到下,参照如下:

class MyProxyStyle : public QProxyStyle
{
	Q_OBJECT

public:
	MyProxyStyle(QStyle *parent=0);
	~MyProxyStyle();

	void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const;
private:
	
};

MyProxyStyle::MyProxyStyle(QStyle *parent)
	: QProxyStyle(parent)
{


}


MyProxyStyle::~MyProxyStyle()
{


}

void MyProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
	if (element == CE_TabBarTabLabel)
	{
		if (const QStyleOptionTab *tab = qstyleoption_cast(option))
		{
			QStyleOptionTab opt(*tab);
			opt.shape = QTabBar::RoundedEast;
			QProxyStyle::drawControl(element, &opt, painter, widget);
			return;
		}
	}
	QProxyStyle::drawControl(element, option, painter, widget);
}


ITTabWidget::ITTabWidget(QWidget *parent)
	: QTabWidget(parent)
{
	QWidget* tempwidget1 = new QWidget();
	QWidget* tempwidget2 = new QWidget();
	addTab(tempwidget1,"123456");
	addTab(tempwidget2,"abcdef");
	
	tabBar()->setStyle(new MyProxyStyle());
}




你可能感兴趣的:(QT)