简体   繁体   English

如何防止QTabWidget中的选项卡按钮缩小

[英]How to prevent tab buttons from shrinking in QTabWidget

How do I prevent the tab buttons of a Qt5 QTabWidget from shrinking, thus obscuring the full tab names, when I shrink the containing window? 缩小包含窗口时,如何防止Qt5 QTabWidget的选项卡按钮缩小,从而遮盖了完整的选项卡名称?

Here's a self-contained example of the problem: 这是问题的独立示例:

#include <QApplication>
#include <QMainWindow>
#include <QtGui>
#include <QTableWidget>

QTableWidget*
makeTableWidget( QWidget* parent )
{
    QTableWidget* tableWidget = new QTableWidget( 20, 20, parent );

    for( int irow = 0; irow < 20; irow++ ) {
      for( int icol = 0; icol < 20; icol++ ) {
            QTableWidgetItem* newItem = new QTableWidgetItem( QString( "%1,%2" ).arg( irow ).arg( icol ) );
            tableWidget->setItem( irow, icol, newItem );
      }
    }

    return tableWidget;
}

int
main( int argc, char *argv[] ) {
    QApplication app( argc, argv );

    QMainWindow* mw = new QMainWindow();

    QTabWidget* tabs = new QTabWidget();

    tabs->setUsesScrollButtons( true );

    for( int itab = 0; itab < 10; itab++ ) {
            QTableWidget* tableWidget = makeTableWidget( mw );
            tabs->addTab( tableWidget, QString( "Table%1" ).arg( itab, 2, 10, QLatin1Char( '0' ) ) );
    }

    mw->setCentralWidget( tabs );

    mw->show();

    return app.exec();
}

When the main window is big enough, I can see the full names of each tab: 当主窗口足够大时,我可以看到每个选项卡的全名:

在此处输入图片说明

When I shrink the main window, however, the tab names get shortened with part of each name elided, even though I have enabled scrolling for the tab bar: 但是,当我缩小主窗口时,即使我启用了标签栏的滚动功能,标签名称也会被缩短,每个名称的一部分都被删除了:

在此处输入图片说明

Since the tab-bar scrolling is enabled, it seems like it would work from a UI perspective to keep the tab-names at full size, so the user would be able to read each one unambiguously. 由于启用了选项卡栏滚动功能,因此从UI角度来看,将选项卡名称保持完整大小似乎是可行的,因此用户将能够清楚地阅读每个选项卡名称。

I need to know, however, how to modify the above code so that the tab button names do not shrink and thus get partially elided. 但是,我需要知道如何修改上面的代码,以使选项卡按钮的名称不会缩小,因此会被部分省略。

For the sake of brevity I'll spare description of my many misguided newbie experiments trying to figure this out. 为了简洁起见,我将不去描述我为弄清楚这一点而进行的许多误导新手实验。

Thanks 谢谢

您可以使用以下方式禁用文字省略:

tabs->setElideMode(Qt::ElideNone);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM