Results 1 to 10 of 10

Thread: tabWidget duplicate frames

  1. #1
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default tabWidget duplicate frames

    hello I am marco and I am new in the forum

    I just started with QT but I'm a autodidact programmer c ++ for a long time

    I wanted to create a tab with a distinctive form and each time you create a new tab window I have always the same layout and my basic forms

    Immagine.jpg

    Qt Code:
    1. void MainWindow::on_tabWidget_currentChanged(int index)
    2. {
    3. qDebug() << n_tab;
    4. if (index == n_tab){
    5. ui->tabWidget->setTabText(n_tab, "QString::number(n_tab)");
    6.  
    7. QWidget *tabWidget;
    8. tabWidget = new QWidget;
    9.  
    10. // ===============================================
    11. // copi form from tab 1 end paste on new tabWidget
    12. // ===============================================
    13.  
    14. ui->tabWidget->addTab(tabWidget,"+");
    15. n_tab ++;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    in this case if we press the "+" tab add a new tab
    I would like already I said the nuvo widget is equal to the first


    Thank you in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    Design the page widget as a separate form (New -> Qt -> Qt Designer Form Class) and then create instances of that widget instead of QWidget.

    Cheers,
    _

  3. #3
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    thank you so much
    as associate now my widget class to the new tab?
    tabwidget is my class

    Qt Code:
    1. void MainWindow::on_tabWidget_currentChanged(int index)
    2. {
    3. qDebug() << n_tab;
    4. if (index == n_tab){
    5. ui->tabWidget->setTabText(n_tab, "new");
    6.  
    7. tabSerial *tabWidget;
    8. tabWidget = new tabSerial;
    9.  
    10. ui->tabWidget->addTab(tabWidget,"+");
    11. n_tab ++;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    I am not sure what you are asking, this looks ok.

    Three things I would have done differently:
    - ui->tabwidget->count() instead of n_tab, no point in risking a variable getting out of syn
    - TabSerial instead of tabSerial, classes usually start with an upper case character in Qt apps
    - avoid using of "connect by name" and use explicit connect() instead.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    ok sorry

    I modified the class as you told me but I did not understand how to use the connect ()

    Qt Code:
    1. void MainWindow::on_tabWidget_currentChanged(int index)
    2. {
    3. qDebug() << index;
    4. if (index == ui->tabWidget->count()-1){
    5. ui->tabWidget->setTabText(ui->tabWidget->count()-1, "port");
    6. tabWidget *serialtab;
    7. serialtab = new tabWidget();
    8.  
    9. ui->tabWidget->addTab(serialtab,"+");
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    now my class isthis
    Immagine.jpg

    please can help me with an example

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    The explicit connect would look something like this
    Qt Code:
    1. MainWindow::MainWindow(QWidget* parent)
    2. : QMainWindow(parent)
    3. , ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::onCurrentTabChanged);
    8. }
    To copy to clipboard, switch view to plain text mode 
    where onCurrentTabChanged would be the function you currently have, just with a different name. Can be any valid method name in that class.

    Cheers,
    _

  7. #7
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    really thank you for your patience.

    I'm sorry but I have not figured out how to attach my widget to the new tab.

    in my example the new tab windows are always empty and you do not see the widget

  8. #8
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Platforms
    Symbian S60

    Default Re: tabWidget duplicate frames

    where will you run the tab ?

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    Quote Originally Posted by ilmandorlone View Post
    I'm sorry but I have not figured out how to attach my widget to the new tab.

    in my example the new tab windows are always empty and you do not see the widget
    addTab() should do that.
    Does your widget work stand alone?
    E.g. testing as a separate window by calling serialTab->show() instead of passing it to addTab?

    Cheers,
    _

  10. #10
    Join Date
    Mar 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tabWidget duplicate frames

    you can see my screensaver of my UI class
    Immagine.jpg

    and this is the cpp file of the class

    Qt Code:
    1. #include "tabwidget.h"
    2. #include "ui_tabwidget.h"
    3.  
    4. tabWidget::tabWidget(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::tabWidget)
    7. {
    8. ui->setupUi(this);
    9. }
    10.  
    11. tabWidget::~tabWidget()
    12. {
    13. delete ui;
    14. }
    To copy to clipboard, switch view to plain text mode 

    then in mainwindow.cpp I include the class with
    Qt Code:
    1. #include "tabwidget.h"
    To copy to clipboard, switch view to plain text mode 

    in the end always How do I create a new tab using my widget class, but the whole thing does not work
    Qt Code:
    1. tabWidget *serialtab;
    2. serialtab = new tabWidget();
    3.  
    4. ui->tabWidget->addTab(serialtab,"+");
    To copy to clipboard, switch view to plain text mode 


    I hope I misunderstood your question, thanks


    Added after 21 minutes:


    very sorry.
    the problem was that the first 2 tabs are already created by mainwindow.ui but did not have the calss TabWidget created by me but the third tab it works !!!

    thank you very much !!!
    Last edited by ilmandorlone; 16th March 2016 at 11:54.

Similar Threads

  1. Qt emit keyword duplicate
    By mreyfout in forum Qt Programming
    Replies: 2
    Last Post: 20th October 2010, 06:10
  2. duplicate recordset
    By sepehr in forum Qt Programming
    Replies: 2
    Last Post: 4th February 2009, 11:44
  3. Duplicate SLOTS
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2008, 13:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.