【发布时间】:2019-10-29 21:17:12
【问题描述】:
在 QtCreator 中,我在画布上添加了一个带有两列的 Tree Widget。这创建了如下 XML:-
<widget class="QTreeWidget" name="postgresTree">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>851</width>
<height>471</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="allColumnsShowFocus">
<bool>false</bool>
</property>
<property name="columnCount">
<number>2</number>
</property>
<column>
<property name="text">
<string notr="true">Schema</string>
</property>
</column>
<column>
<property name="text">
<string notr="true">Table</string>
</property>
</column>
然后我填充了这个:-
QSqlQuery query;
query.exec("SELECT schema_name FROM information_schema.schemata");
while(query.next()) {
QString schema = query.value(0).toString();
QTreeWidgetItem *schema_branch = new QTreeWidgetItem(ui->postgresTree);
schema_branch->setText(0,schema);
schema_branch->setText(1,QString("Table"));
//Get table list for schema
QSqlQuery table_query;
table_query.exec(QString("SELECT tablename FROM pg_tables where schemaname = '%1'").arg(schema));
while(table_query.next()) {
QString table = table_query.value(0).toString();
QTreeWidgetItem *table_branch = new QTreeWidgetItem(ui->postgresTree);
table_branch->setText(1,table);
schema_branch->addChild(table_branch);
}
ui->postgresTree->addTopLevelItem(schema_branch);
}
这可行,但在我的树中给了我一个固定的布局,没有展开/折叠句柄。我希望能够在表格列折叠并显示展开/折叠控件的情况下查看此树。我该怎么做?
【问题讨论】:
标签: qt qtreewidget qtreewidgetitem