简体   繁体   English

在Qt中创建用户表

[英]Creating a user table in Qt

I want to add to my project a possibility of a user creating his own table, where he/she could choose the number of columns, add their name and choose the type for each column. 我想将用户创建自己的表的可能性添加到我的项目中,他/她可以在其中选择列数,添加列名并为每列选择类型。 The idea is, that value of a number is got from lineEdit, names as well and type from a comboBox. 这个想法是,一个数字的值是从lineEdit中获得的,名称也可以从comboBox中获得。 How can I do it in QtCreator using c++? 如何使用c ++在QtCreator中做到这一点?

I'm really new in that, so, I'm open to any option and I'd like to have a direct answer with an explanation. 我真的很新,因此,我可以接受任何选择,我想直接给出答案并给出解释。 Thanks! 谢谢!

If you want create a table with "QTableWidget" you can make this with 如果要使用“ QTableWidget”创建表,可以使用

QTableWidget tableWidget = new QTableWidget(this);
tableWidget->setColumnCount( numberCols );

now you can set header of columns with: 现在,您可以使用以下命令设置列标题:

tableWidget->setHorizontalHeaderLabels(m_tableHeader);

where tableHeader is a array of titles. 其中tableHeader是标题数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM