Qobject have eventfilter, function very strong (arbitrary processing, such as to qlineedit participle)

Source: Internet
Author: User

I believe everyone has used a dictionary! Because English is not very good ... O (∩_∩) o~, so often the translation of the word!

    • Briefly
    • Realize
      • Effect
      • Source
    • More references

Realize

Principle: Move the mouse over a word, get the mouse position, and then in the corresponding position to take the word, translation!

Based on this principle, we implement a qtooltip for each word.

Effect

Source

Create Qtextedit formations, and then listen to events through Installeventfilter.

M_ptextedit= new qtextedit (this); M_ptextedit- >setobjectname ( "Highlightlabel"); M_ptextedit->append ( Qstring::fromlocal8bit ( "one go, two or three Miles"); m_ptextedit ->append (Qstring::fromlocal8bit ( " Youth is not old, struggle not only! ")); M_ptextedit->append (Qstring::fromlocal8bit (" You were not alone. ")); M_ptextedit->append (Qstring::fromlocal8bit ( //Install event filter M_ptextedit->installeventfilter (this);   

Implement EventFilter, Judge the event type is Qevent::tooltip, get the cursor, take the word.

BOOL MainWindow:: EventFilter (Qobject*obj, Qevent*event) {if (obj= = M_ptextedit) {Event is a hintif (event-Type ()= = Qevent:: ToolTip) {qhelpevent*phelpevent = static_cast<qhelpevent *> (event); //Get cursor qtextcursor cursor = m_ptextedit->cursorforposition (phelpevent->pos ()); cursor.  Select (Qtextcursor:: wordundercursor);//real participle //Display message Qtooltip:: Showtext (Phelpevent- Globalpos (), cursor. SelectedText ()); return true;}} return qdialog:: EventFilter (obj, event);}            

If you are unfamiliar with event filtering, see more references.

http://blog.csdn.net/liang19890820/article/details/51804098

Qobject have eventfilter, function very strong (arbitrary processing, such as to qlineedit participle)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.