Results 1 to 4 of 4

Thread: QStackedWidget and QTabWidget Structure Advice

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    5

    Default QStackedWidget and QTabWidget Structure Advice

    I am developing an application that is essentially a way of entering data into many SQL tables in a structured format.

    The current layout consists of a QStackedWidget driven by a QListView which contains the tables within the database structure. There will be about 15 pages in the stacked widget.

    On each QStackedWidget page is a QTabWidget, each tab of which contains a some of the fields from the table, or perhaps links to one of the other tables. Each tab widget has approx. 5 tabs with approx 10 fields per tab.

    If I follow this approach, the result a QMainWindow with approximately 15 x 5 x 10 = 750 widgets + container widgets and labels. Whilst 1000+ widgets in a medium sized application is not unreasonable - having them all in one QMainWindow subclass seems a bit crazy!

    My thoughts are to promote each tab to a QWidget subclass which provides all the functionality for that tab page. The problem is though that I like Qt Designer, but all the widgets are children of main window's ui.

    I would welcome any comments on how best to structure this monster!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QStackedWidget and QTabWidget Structure Advice

    Create a QWidget derived class, using Designer, for each stacked widget page content. Using Designer for the main window (list view and stacked widget) use a promoted QWidget to insert each of the custom widgets into the stacked widget.

  3. The following user says thank you to ChrisW67 for this useful post:

    certqt (16th November 2010)

  4. #3
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStackedWidget and QTabWidget Structure Advice

    Hi,

    For each QStackedWidget page you need, create a dialog instead that contains the tabwidget with approximately 5 tabs.
    Create your main dialog or mainwindow, and put a QStackedWidget on it.
    Instantiate each of you dialogs, and add them to the QStackedWidget.

    This way you can easily create your different screens visually in Designer without creating a class with a giant number of widgets in it.

    Code snippets from a project of mine :

    Qt Code:
    1. frmRealParts = new CRealPartsForm(this); // add form with Real parts
    2. ui->twComponents->addTab( frmRealParts, "Realparts" );
    3. frmDistParts = new CDistPartsForm(this); // add form with Distributer parts
    4. ui->twComponents->addTab( frmDistParts, "Distributer" );
    To copy to clipboard, switch view to plain text mode 

    I use a tabwidget (ui->twComponents) to put other dialogs in (CRealPartsForm and CDistPartsForm, which are just dialogs). QStackedWidget has a similar method addWidget() afaik. This code is put in the constructor of my main form, after the ui->setupUI(this);

    Best regards,
    Marc

  5. The following 2 users say thank you to marcvanriet for this useful post:

    certqt (16th November 2010), crsn (22nd March 2011)

  6. #4
    Join Date
    Sep 2010
    Posts
    14
    Thanks
    5

    Default Re: QStackedWidget and QTabWidget Structure Advice

    Chris, Marc, thank you for your helpful insight.

    Marc, your solution is the perfect one for me, as you suggest addWidget does the job:

    Qt Code:
    1. frmRealParts = new CRealPartsForm(this); // add form with Real parts
    2. ui->stackedWidget->addWidget( frmRealParts, "Realparts" );
    3. frmDistParts = new CDistPartsForm(this); // add form with Distributor parts
    4. ui->stackedWidget->addWidget( frmDistParts, "Distributor" );
    To copy to clipboard, switch view to plain text mode 

    Apart from improved partitioning in the designer and code, this approach also has two other very real advantages for me:

    1. I can add tabs and stacked widget pages on the fly as the user requires them;
    2. If it turns out the UI is better served for some pages as a modal / modeless dialog, I can just call ->exec() or ->show() instead!

    Thanks again!

Similar Threads

  1. problem with QStackedwidget
    By psantofe in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2010, 12:41
  2. Help with QStackedWidget
    By onírico in forum Newbie
    Replies: 6
    Last Post: 12th November 2009, 16:34
  3. Some advice on how to structure this program?
    By mrwooster in forum Newbie
    Replies: 13
    Last Post: 12th August 2009, 14:24
  4. Forms or QStackedWidget
    By hgedek in forum Newbie
    Replies: 1
    Last Post: 5th November 2007, 21:35
  5. QStackedLayout vs. QStackedWidget
    By bruccutler in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2007, 23:43

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.