为什么我的QLineEdit和QPushButton之间不能用左右键控制呢???(请大侠们快点指教~怎么没人回呢?急的...)

woshimibao 2010-03-12 01:20:41
为什么我的QLineEdit和QPushButton之间不能用左右键控制呢???(公司不要我用tab键,只要左右键)

我的代码...
QsmpFind.cpp:

void QsmpFind::keyPressEvent(QKeyEvent *event){
if(event->key()==Qt::Key_Down)
{ movePrevious();
}
if(event->key() == Qt::Key_Up)
{ moveNext();
}

//hope can use left & right key...
if(event->key()==Qt::Key_Left)
{ movePrevious();
}
if(event->key() == Qt::Key_Right)
{ moveNext();
}
}

void QsmpFind::setLocation(int i){
widgetLocation=i;
}

int QsmpFind::getLocation(){
return widgetLocation;
}

void QsmpFind::activeWidget(int i){
if(i%2!=0){
lineEditFind->setReadOnly(true);
}
else if(i%2==0){
lineEditFind->setReadOnly(false);
}
}

void QsmpFind::movePrevious(){
--widgetLocation;
setLocation(widgetLocation);
activeWidget(getLocation());
}

void QsmpFind::moveNext(){
++widgetLocation;
setLocation(widgetLocation);
activeWidget(getLocation());
}

上下键和左右键调用的是同样的方法,但是为什么左右键就是不起作用,我知道肯定是因为QEditLine的输入关系,但是最最关键的解决方法不知道...哪位大虾帮帮小妹啊!!!
(刚学qt,如果觉得编的很蠢,千万不要嘲笑啊...)
...全文
96 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
woshimibao 2010-03-15
  • 打赏
  • 举报
回复
多谢指教,但是我的还是不可以,我想会不会是因为我并不是两个QLineEdit在转换,而是一个换成了QPushButton的关系...
chenfeng2002 2010-03-12
  • 打赏
  • 举报
回复
lineEdit中的左右键默认是在框中移动,改为如下(我就是怎么干的):

if(event->key()==Qt::Key_Left)
{

focusNextChild();
}

if(event->key() == Qt::Key_Right)
{
focusPreviousChild();
}

16,235

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧