Add widget in code
-
I can successfully add new tab and insert a sub tab into it.
I do not see a function to add / insert ANY widgets to the sub tab, just another tab .void Form_Widget_HCI::on_lineEdit_2_returnPressed() { // create new tab QTabWidget *tab = new QTabWidget(); ui->tabWidget->addTab(tab, "New tab test"); // create subtab QTabWidget *tab_sub = new QTabWidget(); // create widget QTextEdit *text = new QTextEdit(); tab->addTab(tab_sub,"Test subtab"); **// add widget to subtab ???** ??
-
Hi,
tab_sub->addTab(text, tr("Text Edit"));
-
@SGaist said in Add widget in code:
tab_sub->addTab(text, tr("Text Edit"));
Ok, this actually creates / adds a tab , which is nice.
Where do I look for "tr" description ?Here is partially what I have
// create new (main) tab
QTabWidget *tab = new QTabWidget();
ui->tabWidget->addTab(tab, "New tab test");
// create subtab
QTabWidget *tab_sub = new QTabWidget();
// create widget
QTextEdit *text = new QTextEdit();
tab->addTab(tab_sub,"Test subtab");Yes, this is "confusing" - I read it as "adding tab / page (with tile "Text Edit ') and widget.
BTW the QTextEdit takes full space on the page.
So far no "layout" needed - unless I add more widgets to new page .. Right ?
tab_sub->addTab(text, tr("Text Edit")); text->append("Append text ");
Addendum
I have made some changes and realized I do not need the "sub tab " .l
Not sure how to change`this code// create widget QTextEdit *text = new QTextEdit(); // create new tab QTabWidget *tab = new QTabWidget(); text->setText("The quick brown fox jumps over lazy dog"); // tab->addTab(text, tr("Text Edit")); // text->append("Append text "); // add a new page to existing tab ui->tabWidget->addTab(tab, "New tab test"); // add widget to main tab // create subtab // QTabWidget *tab_sub = new QTabWidget(); // tab->addTab(tab_sub,"Test subtab"); // created unwnated sub tab tab->addTab(text, tr("Text Edit")); text->append("Append text "); //#endif
-
tr is used for text translation. It's an old habit of mine to write my code so that translation can be implemented at anytime.
As for your use case, just nuke your "tab" object and add text directly to your ui QTabWidget:
ui->tabWidget->addTab(text, tr("Text Edit"));