February 10, 2011

annatz annatz
Lab Rat
37 posts

QMainWindow

 

I have created a main window with a qvboxlayout where I have placed a combobox, a tree widget and the button ok. When I click the button ok, I create a new qvboxlayout with some widgets. The new qvboxlayout has the button return. How can I return to the first window with the choices of the user?
Do I have to create a new MainWindow or is there a function that does the whole work?

The code is :

  1. QXSRExample::QXSRExample(QWidget *parent) : QMainWindow(parent) {
  2.     setupUI();
  3. }
  4. QXSRExample::~QXSRExample() {
  5. }
  6. void QXSRExample::setupUI() {
  7.      QFrame* frame = new QFrame(this);
  8.  
  9.     _layout = new QVBoxLayout;
  10.  
  11.     frame->setLayout(_layout);
  12.  
  13.     parseXML();
  14.  
  15.     QScrollArea* scrollArea = new QScrollArea;
  16.  
  17.     scrollArea->setWidget(frame);
  18.  
  19.     scrollArea->setWidgetResizable(true);
  20.  
  21.     setCentralWidget(scrollArea);
  22. }
  23.  
  24. ………
  25.  
  26. void QXSRExample::details(QTreeWidgetItem* item,int column){
  27.  
  28.     itemName= item->data(column, Qt::DisplayRole).toString();
  29.  
  30.     QFrame* frame2 = new QFrame(this);
  31.  
  32.     _layout = new QVBoxLayout;
  33.  
  34.     frame2->setLayout(_layout);
  35.  
  36.         QScrollArea* scrollArea = new QScrollArea;
  37.  
  38.     scrollArea->setWidget(frame2);
  39.  
  40.     scrollArea->setWidgetResizable(true);
  41.  
  42.     setCentralWidget(scrollArea);
  43.  
  44.    
  45.     while(!persons3.isEmpty()) {
  46.  
  47.         QMap<QString,QString> person = persons3.takeFirst();
  48.  
  49.         if ((person["surname"]==itemName) or (person["name"]==itemName)){
  50.  
  51.             QGroupBox* personGB = new QGroupBox("Patient");
  52.  
  53.             QFormLayout* layout = new QFormLayout;
  54.  
  55.             layout->addRow("ID", new QLineEdit(person["id"]));
  56.  
  57.             ………….
  58.             personGB->setLayout(layout);
  59.  
  60.             this->_layout->addWidget(personGB);
  61.  
  62.         }
  63.     }
  64.      QPushButton* ok = new QPushButton("Return");
  65.  
  66.      _layout->addWidget(ok, 1, Qt::AlignCenter);
  67.  
  68.      connect(ok, SIGNAL(clicked()),this, SLOT(cancel()));
  69. }

EDIT: please only use one @-tag in the beginning of the code, and one in the end, Gerolf

2 replies

February 10, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

hi, can u fix the code format by enclosing it with @ tag? not readable right now

February 10, 2011

Gerolf Gerolf
Robot Herder
3287 posts

you replace the centralWidget of the main window, so you must move it back.
An other option woukd be to use a stacked widget (QStackedWidget) and switch between them.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ model-view and more switch      DBus adaptor slots with ’const QDBusMessege &messege’ argument. ››

You must log in to post a reply. Not a member yet? Register here!