//
//表格表头的显示与隐藏
tableWidget->verticalHeader()->setVisible(false) //隐藏列表头
tableWidget->horizontalHeader()->setVisible(false)//隐藏行表头
//tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers)
//设置行高
for(int i= 0i<tableWidget->rowCount()i++)
{
tableWidget->setRowHeight(i, 60)
}
//设置列宽
for(int i= 0i<tableWidget->columnCount()i++)
{
tableWidget->setColumnWidth(i, 185)
}
QLabel* label = new QLabel("gender")
QComboBox *comBox = new QComboBox()
comBox->setFixedSize(100, 25)
comBox->addItem("F")
comBox->addItem("M")
// 单元格中的控件需要通过布局管理
QWidget *widget = new QWidget
QHBoxLayout *hLayout
hLayout = new QHBoxLayout()
hLayout->addWidget( label)
hLayout->addWidget(comBox)
hLayout->setMargin(0)
hLayout->setAlignment(widget, Qt::AlignCenter)
hLayout->setContentsMargins(10, 0, 20, 0)
widget->setLayout(hLayout)
// 添加单元格
tableWidget->setCellWidget(0,0,widget)
QHBoxLayout* mainLayout = new QHBoxLayout
mainLayout->addWidget( tableWidget)
setLayout(mainLayout)
首先,我们要编写一个主动态库,来实现我们自己的控件。其次,还要写一个接口动态库,用来实现designer中调用我们自己的控件。这一步很关键。这个动态库中程序结构都是qt固定的。具体参见附录。
最后,编译写好的上面两个插件,要拷贝一些文件到相应目录下:
分别将主动态库和库文件拷贝到qt安装的bin和lib目录下;
将接口动态库和库文件拷贝到qt安装目录的plugins\designer目录下;
将主动态库的接口头文件拷贝到qt安装目录的include目录下;
这样,我们的写的控件就添加完成了。这时打开desinger就可以在工具条中看到我们写的控件了。我们就可以像其它控件一样使用这个控件了。
可以,你可以参考assitant中的说明void QListWidget::setItemWidget(QListWidgetItem * item, QWidget * widget)
Sets the widget to be displayed in the given item.
This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.
上面的翻译:
该函数应该只用来在一个list widget item位置显示静态内容。如果你想要显示自定义动态内容或实现一个自定义编辑控件,使用QListView和子类化QItemDelegate代替。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)