Frage

I working on one application and I have problem with tab name. When I click on push button (NEW) I want to dynamically create new tab.

With this function i create new file:

bool MainWindow::toolbarNewFile()
{

    QWidget *page = new QWidget;

    QTextEdit *codeEditor = new QTextEdit;

    QGridLayout *layout = new QGridLayout;

    layout->addWidget(codeEditor);

    page->setLayout(layout);

    tab_widget->addTab(page,"File");

    return true;
}

But all tabs have name "FILE"

How to set in tab name number. When i make new tab auto set number of the tab like this.

File-1, File-2, File-3

I try to set counter i=0; and in addTab(page,"File-"+ i++); Doesn't work.

War es hilfreich?

Lösung

You need to covert integer to the QString to be able to concat it to the QString. Even better, you can use QString::arg function and get readable and potentially faster code very easily:

tab_widget->addTab(page, QString("File-%1").arg(i++));

Where i is field in your class initialized to 1.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top