如何在QTabWidget Qt中扩展选项卡 [英] How to expand tabs in QTabWidget Qt
本文介绍了如何在QTabWidget Qt中扩展选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的QTabWidget
:
但是我想扩展选项卡以填充"整个小部件宽度,如下所示:
But I want to expand the tabs to "fill" the entire widget width, like this:
我该怎么做?
我正在使用 Qt 5.3.2 和 Qt Creator 3.2.1
更新:
我尝试使用setExpanding
函数:
ui->myTabWidget->tabBar()->setExpanding(true);
但这没用.
推荐答案
As mostefa answered here, I can set a fixed width for the tabs using styleSheet.
我正在根据QTabWidget
宽度计算宽度.
I am calculating the width based on the QTabWidget
width.
要正确获取QTabWidget
宽度,我需要在showEvent
函数中获取它:
To get the QTabWidget
width correctly I need to get it in the showEvent
function:
void LogListForm::showEvent(QShowEvent *ev)
{
/*
* Divide by 2 because we have 2 tabs.
* I need to decrease 24 pixels to fill the width correctly.
*/
int tabWidth = (ui->myTabWidget->width()/2)-24;
/*
* Then, I set this tabWidth to the styleSheet.
* Note: I need to set the previously styleSheet to not lose it
*/
ui->myTabWidget->setStyleSheet( ui->myTabWidget->styleSheet() +
"QTabBar::tab {"
"width: " + QString::number(tabWidth) + "px; }" );
}
这篇关于如何在QTabWidget Qt中扩展选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文