Results 1 to 9 of 9

Thread: Problem using QTabWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem using QTabWidget

    Hi All...
    Thanks very much for both suggestions. I will try to make my code better.

    I have pass through the including library and code into the project directly in the CMakeLists.txt but even if i use in the currentChange method this code

    Qt Code:
    1. qApp->processEvents(QEventLoop::AllEvents);
    To copy to clipboard, switch view to plain text mode 

    when i switch from one page of the tab to another the content is fused togheter...

    Anyone had this problem and know how to help my out of this situation?

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem using QTabWidget

    The code that you have shown works fine with a couple of tweaks:
    Qt Code:
    1. #include <QtGui>
    2. class MyTabWidget : public QTabWidget
    3. {
    4. Q_OBJECT
    5. public:
    6. MyTabWidget(QWidget *parent = 0) : QTabWidget(parent) {
    7. qDebug() << "created";
    8. }
    9. public slots:
    10. void prova(int index){
    11. QMessageBox* msg = new QMessageBox(this->parentWidget());
    12. msg->setWindowTitle("Hello !");
    13. msg->setText("Selected Tab index is : "+ QString::number(index));
    14. msg->show();
    15. }
    16. };
    17.  
    18. int main(int argc, char *argv[]){
    19. QApplication app(argc, argv);
    20. QWidget *centralWidget = new QWidget(&w);
    21. centralWidget->setFixedSize(1200,800);
    22. MyTabWidget *tabs = new MyTabWidget(centralWidget);
    23. tabs->setDocumentMode(true);
    24. tabs->setFixedSize(1200, 200);
    25. tabs->addTab(new QLabel("Page 1"),"Controllo");
    26. tabs->addTab(new QLabel("Page 2"),"Registrazione");
    27. tabs->setTabsClosable(false);
    28. QObject::connect(tabs,SIGNAL(currentChanged(int)),tabs,SLOT(prova(int)));
    29. w.setCentralWidget(centralWidget);
    30. w.show();
    31. return app.exec();
    32. }
    33. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

    What do "window" and "window0" point to?

  3. #3
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem using QTabWidget

    So i show you all the code:

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "registrazione.h"
    3. #include <QtGui>
    4. #include <vtkSmartPointer.h>
    5. #include <vtkSphereSource.h>
    6. #include <vtkPolyDataMapper.h>
    7. #include <vtkActor.h>
    8. #include <vtkImageViewer.h>
    9. #include <vtkRenderWindowInteractor.h>
    10. #include <vtkInteractorStyleImage.h>
    11. #include <vtkRenderer.h>
    12. #include <vtkJPEGReader.h>
    13. #include <QCheckBox>
    14. #include <QVTKWidget.h>
    15. #include "MyTabWidget.h"
    16.  
    17.  
    18. using namespace std;
    19.  
    20.  
    21. int main(int argc, char *argv[]){
    22.  
    23.  
    24. QApplication a(argc, argv);
    25.  
    26. MainWindow w;
    27.  
    28. QPushButton *Dati = new QPushButton("Inserisci dati");
    29. Dati->setFixedHeight(20);
    30. Dati->setFixedWidth(150);
    31.  
    32. QPushButton *Registrazione = new QPushButton("Avvia registrazione");
    33. Registrazione->setFixedHeight(20);
    34. Registrazione->setFixedWidth(150);
    35. Registrazione->setEnabled(false);
    36.  
    37. QPushButton *Seleziona = new QPushButton("Point Pick");
    38. Seleziona->setEnabled(false);
    39. Seleziona->setFixedHeight(20);
    40. Seleziona->setFixedWidth(150);
    41.  
    42. QPushButton *impS = new QPushButton("Cambia source");
    43. impS->setFixedHeight(20);
    44. impS->setFixedWidth(150);
    45.  
    46. QPushButton *impT = new QPushButton("Cambia target");
    47. impT->setFixedHeight(20);
    48. impT->setFixedWidth(150);
    49.  
    50. QPushButton *Carica = new QPushButton("Carica PCD");
    51. Carica->setFixedHeight(20);
    52. Carica->setFixedWidth(150);
    53.  
    54. QPushButton *Controlla = new QPushButton("Controlla");
    55. Controlla->setFixedHeight(20);
    56. Controlla->setFixedWidth(150);
    57. Controlla->setEnabled(false);
    58.  
    59. QLabel *l0 = new QLabel("Posizione della point cloud da controllare");
    60.  
    61. QLabel *l1 = new QLabel("Posizione della point cloud sorgente");
    62.  
    63. QLabel *l2 = new QLabel("Posizione della point cloud destinazione");
    64.  
    65. QLabel *interazioni = new QLabel("Interazioni: ");
    66. interazioni->setFixedWidth(150);
    67. QTextEdit *testo0 = new QTextEdit("");
    68. testo0->verticalScrollBar()->setVisible(false);
    69. testo0->setFixedHeight(20);
    70. testo0->setFixedWidth(300);
    71. testo0->setEnabled(false);
    72.  
    73.  
    74. QTextEdit *testo1 = new QTextEdit("");
    75. testo1->verticalScrollBar()->setVisible(false);
    76. testo1->setFixedHeight(20);
    77. testo1->setFixedWidth(300);
    78. testo1->setEnabled(false);
    79.  
    80. QTextEdit *testo2 = new QTextEdit("");
    81. testo2->setFixedHeight(20);
    82. testo2->setFixedWidth(300);
    83. testo2->setEnabled(false);
    84. testo2->verticalScrollBar()->setVisible(false);
    85.  
    86. QVTKWidget *widget0 = new QVTKWidget;
    87. widget0->setVisible(false);
    88.  
    89.  
    90. QVTKWidget *widget = new QVTKWidget;
    91. widget->setVisible(false);
    92.  
    93.  
    94. QWidget *window0 = new QWidget();
    95.  
    96. QWidget *window = new QWidget();
    97.  
    98. QHBoxLayout *ly0 = new QHBoxLayout();
    99. ly0->addWidget(l0);
    100. ly0->addWidget(testo0);
    101. ly0->addWidget(Carica);
    102. ly0->addWidget(Controlla);
    103.  
    104. QHBoxLayout *ly1 = new QHBoxLayout();
    105. ly1->addWidget(l1);
    106. ly1->addWidget(l2);
    107.  
    108. QHBoxLayout *ly2 = new QHBoxLayout();
    109. ly2->addWidget(testo1);
    110. ly2->addWidget(impS);
    111. ly2->addWidget(testo2);
    112. ly2->addWidget(impT);
    113.  
    114.  
    115. QHBoxLayout *ly3 = new QHBoxLayout();
    116. ly3->addWidget(interazioni);
    117. ly3->addWidget(Registrazione);
    118. ly3->addWidget(Seleziona);
    119.  
    120.  
    121. QVBoxLayout *layout0 = new QVBoxLayout();
    122. layout0->addLayout(ly0);
    123. layout0->addWidget(widget0);
    124.  
    125. QVBoxLayout *layout = new QVBoxLayout();
    126. layout->addWidget(Dati);
    127. layout->addLayout(ly1); layout->addLayout(ly2); layout->addLayout(ly3);
    128. layout->addWidget(widget);
    129.  
    130.  
    131. window0->setLayout(layout0);
    132. window0->setGeometry(1000,0,1200,800);
    133. window->setVisible(false);
    134. window0->show();
    135.  
    136.  
    137. window->setLayout(layout);
    138. window->setGeometry(1000,0,1200,800);
    139. window->setVisible(false);
    140. window->show();
    141.  
    142. QWidget *centralWidget = new QWidget(&w);
    143. centralWidget->setFixedSize(1200,200);
    144.  
    145.  
    146. MyTabWidget *tabs = new MyTabWidget(centralWidget);
    147. tabs->setDocumentMode(false);
    148. tabs->setFixedSize(1200, 800);
    149. tabs->addTab(window0,"Controllo");
    150. tabs->addTab(window,"Registrazione");
    151. tabs->setTabsClosable(false);
    152. tabs->update();
    153. QObject::connect(tabs,SIGNAL(currentChanged(int)),tabs,SLOT(prova(int)));
    154.  
    155. w.setCentralWidget(centralWidget);
    156. w.setGeometry(1000,0,1200,800);
    157. w.setWindowTitle("Progetto di Elaborazione tridimensionale");
    158. w.show();
    159.  
    160. w.setVisualizer(testo0, Carica,Controlla, widget0);
    161. w.setVisualizer(Dati, Registrazione,testo1,testo2,widget,impS,impT,Seleziona);//, Plan, Radious);
    162.  
    163. return a.exec();
    164. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Problem using QTabWidget

    What does the setVisualizer method do?

  5. #5
    Join Date
    Sep 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem using QTabWidget

    Qt Code:
    1. void MainWindow::setVisualizer(QTextEdit *t0, QPushButton *c, QPushButton *ct, QVTKWidget *w){
    2. testo0 = t0;
    3. Cambia = c;
    4. Controlla = ct;
    5. finestra0 = w;
    6.  
    7. QObject::connect(c, SIGNAL(clicked()), this ,SLOT(impostaC()));
    8. QObject::connect(ct, SIGNAL(clicked()), this ,SLOT(controllaPCD()));
    9. //finestra0->show();
    10. //aggiornaFinestra(daControllare,finestra0);
    11. }
    12.  
    13. void MainWindow::setVisualizer(QPushButton *d, QPushButton *r, QTextEdit *t1, QTextEdit *t2, QVTKWidget *w, QPushButton *s, QPushButton *t, QPushButton *sel, QWidget *lgr){
    14. Dati = d; //inserire entrambi i percorsi contemporaneamente
    15. Registrazione = r; //bottone che avvia la registrazione
    16. ImpS=s; //cambiare percorso sorgente
    17. ImpT=t; //cambiare percorso target
    18. Seleziona=sel; //bottone selezione pointPick
    19. testo1 = t1; //inserimento percorso source
    20. testo2 = t2; //inserimento percorso target
    21. finestra = w;
    22. loggerBase=lgr;
    23.  
    24. //routine di risposta
    25. QObject::connect(d, SIGNAL(clicked()), this ,SLOT(reg()));
    26. QObject::connect(r, SIGNAL(clicked()), this ,SLOT(esegui()));
    27. QObject::connect(s, SIGNAL(clicked()), this ,SLOT(impostaS()));
    28. QObject::connect(t, SIGNAL(clicked()), this ,SLOT(impostaT()));
    29. QObject::connect(sel, SIGNAL(clicked()), this ,SLOT(selezionatore()));
    30.  
    31. //aggiornaFinestra(daControllare,finestra);
    32. //rendere visibile la finestra di
    33. //finestra->setVisible(true);
    34. //finestra->show();
    35. return;
    36. }
    To copy to clipboard, switch view to plain text mode 

    This is the code, is a method of union from the main code and the class MainWindow, it simply set the pointer to the Widget in main.cpp and create the slot for some signal

Similar Threads

  1. QTabWidget problem
    By alan lenton in forum Qt Programming
    Replies: 5
    Last Post: 25th July 2016, 16:16
  2. Replies: 6
    Last Post: 21st August 2013, 12:53
  3. Problem with QTabWidget
    By alizadeh91 in forum Qt Programming
    Replies: 3
    Last Post: 6th August 2012, 11:12
  4. QTabWidget problem
    By hnfmr in forum Qt Programming
    Replies: 4
    Last Post: 25th February 2011, 15:10
  5. QTabWidget problem
    By Strongoloid in forum Newbie
    Replies: 2
    Last Post: 10th September 2009, 20:38

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.