简体   繁体   中英

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?

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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