불행히도 지금은 이것을 테스트 할 수 없으므로 필요한 부분을 가장 잘 추측 할 수 있습니다. 이것은 필자가 입력 한 툴팁에 오류가있는 텍스트 필드를 가지고 있지만 작동해야하는 코드를 기반으로합니다.
이미 마우스 오버 한 상태에서 단어를 선택하라는 코드가 있습니다. 오른쪽에 툴팁이 필요합니다.
textCursor = text.cursorForPosition(event.pos())
textCursor.select(QTextCursor.WordUnderCursor)
text.setTextCursor(textCursor)
word = textCursor.selectedText()
if meetsSomeCondition(word):
toolTipText = toolTipFromWord(word)
# Put the hover over in an easy to read spot
pos = text.cursorRect(text.textCursor()).bottomRight()
# The pos could also be set to event.pos() if you want it directly under the mouse
pos = text.mapToGlobal(pos)
QtGui.QToolTip.showText(pos,toolTipText)
나는 당신이 그 설명하지 않는 한에서 채우기 위해 당신에게 달려 meetsSomeCondition()
및 toolTipFromWord()
왼쪽했지만, 그들은 거기에 갈 필요가 무엇인지 꽤 설명이다.
단어를 선택하지 않고 수행하는 것에 대한 귀하의 의견과 관련하여 가장 쉬운 방법은 새 단어를 선택하고 다시 설정하기 전에 커서를 캐시하는 것입니다. 을 호출 한 다음 이전과 같이 설정하여이 작업을 수행 할 수 있습니다. 그래서 같이
:
oldCur = text.textCursor()
textCursor.select(QTextCursor.WordUnderCursor) # line from above
text.setTextCursor(textCursor) # line from above
word = textCursor.selectedText() # line from above
text.setTextCursor(oldCur)
# if condition as above
당신이 시도 것을 입증하는 몇 가지 예제 코드가 있습니까? –
다시 편집했습니다. – user2638731
밑줄 친 단어에 따라 툴팁이 변경됩니까? 컨텍스트를 좀 더 줄 수 있습니까? –