1

My research into the question suggests that I'm somewhat beating a dead horse, however I can't seem to get a conclusive answer.

I'm using QT Creator to create a GUI that will help interface with a register of units(simple objects, with some ID's and such).

I have a Main Menu, which contains 5 push buttons and a table. Pictured here. My project currently includes these files, and my main currently looks like this:

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    UnitRegister e;
    CommInterface c;
    w.setRegistryPtr(e);
    w.setCommPtr(c);
    w.setTablePtr(w.findChild<QTableWidget*>("unitTable"));

    w.show();

    return a.exec();
}

What I want to do is press one of the four push-buttons on the left, and use that to switch to a different view in the main window.

For this purpose I considered using a QStackedWidget, and then having a page for each menu button. My question is this:

  • How do I/Should I create a separate QT Item Form Class(header, .cpp and .ui file) for each page
  • How do I switch between the pages I've added using the QT Designer.
  • How do I ensure that the different pages can access the UnitRegister created in my main file.

I'm not necessarily searching for a complete answer, but something to get me going.

NT93
  • 316
  • 2
  • 15

1 Answers1

1

Switching Pages: Consider a QButtonGroup to give your buttons ids that you can map to the indexes of your QStackedWidget. Then you can do this:

connect(buttonGroup, SIGNAL(buttonClicked(int)), stackedWidget, SLOT(setCurrentIndex(int)));

Organizing the Pages: Create a .ui file and corresponding container widget for each page in your widget stack. This is much easier than one massive .ui file.

Accessing the UnitRegister: There are tons of ways to do this. Adding a setter function to your classes is one way.

jonspaceharper
  • 4,207
  • 2
  • 22
  • 42