我有一个带有QLineEdit
的对话框窗口,要在我的软件中插入数据,我用键盘上的TAB键从第一个QLineEdit
切换到下一个
我想把背景颜色改成黄色,当焦点被调出时(焦点切换到另一个),它必须回到白色。为此,我在FocusInEvent
和FocusOutEvent
中插入了一个不同的StyleSheet
。在
但我有个问题…
问题是当我把注意力集中在QlineEdit
上时,它会起作用(背景颜色变为黄色),但如果我写了什么,我就切换到下一个QLineEdit
。最后一个^{TextCursor
没有消失,我在窗口中看到两个或更多的文本光标。在
*我省略了部分源代码(如=>;布局、数据库函数等),因为我认为它们与帮助我解决问题无关。在
from PyQt4 import QtGui,QtCore;
class AddWindow(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self);
#Surname
self.SurnameLabel=QtGui.QLabel("Surname:",self);
self.SurnameLabel.move(5,20);
self.SurnameBox=QtGui.QLineEdit(self);
self.SurnameBox.move(5,35);
self.SurnameBox.focusInEvent=self.OnSurnameBoxFocusIn;
self.SurnameBox.focusOutEvent=self.OnSurnameBoxFocusOut;
#Name
self.NameLabel=QtGui.QLabel("Name:",self);
self.NameLabel.move(150,20);
self.NameBox=QtGui.QLineEdit(self);
self.NameBox.move(150,35);
self.NameBox.focusInEvent=self.OnNameBoxFocusIn;
self.NameBox.focusOutEvent=self.OnNameBoxFocusOut;
def OnSurnameBoxFocusIn(self,event):
self.SurnameBox.setStyleSheet("QLineEdit {background-color:yellow}");
def OnSurnameBoxFocusOut(self,event):
self.SurnameBox.setStyleSheet("QLineEdit {background-color:white}");
def OnNameBoxFocusIn(self,event):
self.NameBox.setStyleSheet("QLineEdit {background-color:yellow}");
def OnNameBoxFocusOut(self,event):
self.NameBox.setStyleSheet("QLineEdit {background-color:white}");
问题是你的实现某个事件对光标行为很重要,你的代码已经中断了它。要修正它,请在你的代码成功运行后把旧的行为恢复过来
谨致问候
相关问题 更多 >
编程相关推荐