首页| 论坛| 消息
主题:Qtableview 如何委托实现按下回车到下一行?
lastforest发表于 2020-08-12 20:16
qt 新手一枚。
我想实现给tableview的所有行都委托一个LINEEDIT,设置lineEdit的样式,现在我成功实现了将lineedit委托在QtableView的单元格中,
并限制各行中LINEEDIt的输入,如只能是数字,只能是字母或者其他等等,但是现在在lineedit中按下回车,如何到下一行难住我了,请各位大神指导:
我的委托类的代码如下:
cpp 的代码~

#include "grddelegate.h"#include #include #include #include #include

LineEidtDelegate::LineEidtDelegate(QObject *parent)
: QStyledItemDelegate(parent){ // Frow = row;}
QWidget *LineEidtDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{
QLineEdit *edt = new QLineEdit(parent);
// edt->setStyleSheet("background-color:yellow;border-color:black;border-style:outside;border-width:2px");
edt->setStyleSheet("border: 1px solid rgb(41, 57, 85);\
border-radius: 3px;\
background: white;\
selection-background-color: green;\
font-size: 14px");

switch (index.row()) {case 0:{ //有效值
edt->setValidator(new QIntValidator(0,99999));
connect(edt,SIGNAL(editingFinished()),SLOT(commiteAndClostEditor()));
qDebug()setData(index,text,Qt::DisplayRole|Qt::EditRole);
qDebug()setText(str);
qDebug()
回帖(5):
5楼:是的,终于尝试试成功了。就是用信号
电脑坏了,源码发不上来了。大致是在eventfilter中发射 ..
4楼:lastforest:我是想,能不能在eventFilter里捕获key_Return,然后发射信号,再在主程序里处理,但 ..
3楼:前段时间我也在做相同的需求:
if 按回车键
if 内容合法
if 不是在最后一行,则定位 ..

全部回帖(5)»
最新回帖
收藏本帖
发新帖