Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMainWindow
Qt 6.11 is out! See what's new in the release blog

QMainWindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    annatz
    wrote on last edited by
    #1

    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 :

    @
    QXSRExample::QXSRExample(QWidget parent) : QMainWindow(parent) {
    setupUI();
    }
    QXSRExample::~QXSRExample() {
    }
    void QXSRExample::setupUI() {
    QFrame
    frame = new QFrame(this);

    _layout = new QVBoxLayout;
    
    frame->setLayout(_layout);
    
    parseXML();
    
    QScrollArea* scrollArea = new QScrollArea;
    
    scrollArea->setWidget(frame);
    
    scrollArea->setWidgetResizable(true);
    
    setCentralWidget(scrollArea);
    

    }

    ………

    void QXSRExample::details(QTreeWidgetItem* item,int column){

    itemName= item->data(column, Qt::DisplayRole).toString();
    
    QFrame* frame2 = new QFrame(this);
    
    _layout = new QVBoxLayout;
    
    frame2->setLayout(_layout);
    
        QScrollArea* scrollArea = new QScrollArea;
    
    scrollArea->setWidget(frame2);
    
    scrollArea->setWidgetResizable(true);
    
    setCentralWidget(scrollArea);
    
    
    while(!persons3.isEmpty()) {
    
        QMap<QString,QString> person = persons3.takeFirst();
    
        if ((person["surname"]==itemName) or (person["name"]==itemName)){
    
            QGroupBox* personGB = new QGroupBox("Patient");
    
            QFormLayout* layout = new QFormLayout;
    
            layout->addRow("ID", new QLineEdit(person["id"]));
    
            ………….
            personGB->setLayout(layout);
    
            this->_layout->addWidget(personGB);
    
        }
    }
     QPushButton* ok = new QPushButton("Return");
    
     _layout->addWidget(ok, 1, Qt::AlignCenter);
    
     connect(ok, SIGNAL(clicked()),this, SLOT(cancel()));
    

    }
    @

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

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        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.

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved