Results 1 to 2 of 2

Thread: Separating GUI into classes

  1. #1
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Separating GUI into classes

    I am wanting to neaten up my classes, and need some advise how to proceed.
    Currently in my main file I have

    Qt Code:
    1. {
    2. QApplication app(argc, argv);
    3. Client client;
    4. client.show();
    5. return client.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    In my Client constructor I have

    Qt Code:
    1. QGridLayout *mainLayout = new QGridLayout;
    2. mainLayout->addWidget(inputOptionsGroup(), 1, 0, 1, 2);
    3. mainLayout->addWidget(resultsGroup(), 2, 0, 1, 2);
    4. setLayout(mainLayout);
    To copy to clipboard, switch view to plain text mode 

    and then in resultsGroup (similar to inputOptionsGroup)

    Qt Code:
    1. QGroupBox *Client::resultsGroup()
    2. {
    3. eccentricityLabel = new QLabel(tr("<b>Eccentricity</b>"));
    4. diameterLabel = new QLabel(tr("<b>Diameter</b>"));
    5. eccentricityLineEdit = new QLineEdit("0");
    6. eccentricityLineEdit->setReadOnly(true);
    7. diameterLineEdit = new QLineEdit("0");
    8. diameterLineEdit->setReadOnly(true);
    9. connectionStateLabel = new QLabel("<font color='red'><b>State : Not connected to camera</b></font>");
    10. dbConnectionLabel = new QLabel("<font color='purple'><b>Connecting to MySQL DB...</b></font>");
    11. countLabelPass = new QLabel("<font color='green'><b>Pass : 0</b></font>");
    12. countLabelFail = new QLabel("<font color='red'><b>Fail (Con/Dia/Total) : 0/0/0</b></font>");
    13.  
    14. queryLineEdit = new QLineEdit;
    15.  
    16. QGridLayout *vbox = new QGridLayout;
    17. vbox->addWidget(eccentricityLabel, 0, 0, 1, 1);
    18. vbox->addWidget(eccentricityLineEdit, 0, 1, 1, 1);
    19. vbox->addWidget(diameterLabel, 1, 0, 1, 1);
    20. vbox->addWidget(diameterLineEdit, 1, 1, 1, 1);
    21. vbox->addWidget(connectionStateLabel, 2, 0, 1, 2);
    22. vbox->addWidget(dbConnectionLabel, 3, 0, 1, 2);
    23. vbox->addWidget(queryLineEdit, 4, 0, 1, 2);
    24. vbox->addWidget(countLabelPass,5, 0, 1, 2);
    25. vbox->addWidget(countLabelFail,6, 0, 1, 2);
    26.  
    27. QGroupBox *groupBox = new QGroupBox(tr("Results"));
    28. groupBox->setLayout(vbox);
    29.  
    30. return groupBox;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Essentially I am splitting up the various pieces of the GUI setup into separate functions. I would instead like to move the whole GUI setup to a separate class. I know this is probably simple to some, but I don't know how to do it, and I have been searching.

    My fear is that I am going to fall into problems trying to access various components on the GUI, but I would assumedly get round this using slots/signals.

    Thanks.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Separating GUI into classes

    You can have a look at how Qt generates code out of .ui files.
    You can have something similar if it fits you.

Similar Threads

  1. QT WMI Classes
    By justatiq in forum Qt Programming
    Replies: 31
    Last Post: 10th April 2011, 15:44
  2. Design classes in OOP?
    By vql in forum General Programming
    Replies: 5
    Last Post: 25th October 2007, 14:18
  3. fax classes in qt
    By dyams in forum Qt Programming
    Replies: 5
    Last Post: 7th September 2007, 09:14
  4. Separating QHeaderView from QTableView
    By Jimmy2775 in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2006, 06:47

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.