添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Welcome to Qt Centre .

Qt Centre is a community site devoted to programming in C++ using the Qt framework . Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue — register and post your question.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today !

If you have any problems with the registration process or your account login, please contact us .

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! 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: Switch view
  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" );
frmRealParts = new CRealPartsForm(this);                             // add form with Real parts
ui->twComponents->addTab( frmRealParts, "Realparts" );
frmDistParts = new CDistPartsForm(this);                             // add form with Distributer parts
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,
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: Switch view
  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" );
frmRealParts = new CRealPartsForm(this); // add form with Real parts
ui->stackedWidget->addWidget( frmRealParts, "Realparts" );
frmDistParts = new CDistPartsForm(this); // add form with Distributor parts
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!