Examples: Revamp sql/books

* use nullptr
* use member init
* set ExpandingFieldsGrow fieldGrowthPolicy for QFormLayout, which
makes it behaviors similar on macOS as other platforms
* select first row to make up/down keys works by default

Pick-to: 6.5 6.6
Change-Id: I25d9869d2ca1c7274c2b750aada8270734787546
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Liang Qi 2023-05-15 10:40:56 +02:00
parent 728b991b93
commit ed1fbc7a88
3 changed files with 6 additions and 2 deletions

View File

@ -89,6 +89,7 @@ BookWindow::BookWindow()
); );
ui.bookTable->setCurrentIndex(model->index(0, 0)); ui.bookTable->setCurrentIndex(model->index(0, 0));
ui.bookTable->selectRow(0);
createMenuBar(); createMenuBar();
} }

View File

@ -22,8 +22,8 @@ private slots:
private: private:
void showError(const QSqlError &err); void showError(const QSqlError &err);
Ui::BookWindow ui; Ui::BookWindow ui;
QSqlRelationalTableModel *model; QSqlRelationalTableModel *model = nullptr;
int authorIdx, genreIdx; int authorIdx = 0, genreIdx = 0;
void createMenuBar(); void createMenuBar();
}; };

View File

@ -64,6 +64,9 @@
<string>Details</string> <string>Details</string>
</property> </property>
<layout class="QFormLayout"> <layout class="QFormLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">