Results 1 to 8 of 8

Thread: how to add smilies in QTextEdit

  1. #1
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default how to add smilies in QTextEdit

    hi,

    In QTextEdit if we enter ": )" it needs to change as image .. please guide me if u have any idea?

    Thanks in advance.

    Thanks & Regards,
    Sivambigai.M

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to add smilies in QTextEdit

    React on text changed signals or events.
    Use setHtml and replace the :-) string with some html image tags.

  3. #3
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how to add smilies in QTextEdit

    hi

    Thanks for your idea..

    i have used

    QObject::connect(textEdit, SIGNAL(textChanged()), this, SLOT(changePixmap()),Qt::QueuedConnection) ;

    void CSmsWidget::changePixmap()
    {
    QString text =textEdit->toPlainText();
    if (Qt::mightBeRichText(text)){
    textEdit->setHtml(text);
    }
    }

    but this is not working.. any idea?

    Thanks in advance.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to add smilies in QTextEdit

    Do you think images come out of thin air?

    replace the text :-) with something like <img source="...">

  5. The following user says thank you to tbscope for this useful post:

    chris_helloworld (16th November 2010)

  6. #5
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how to add smilies in QTextEdit

    hi

    Thanks for your reply


    void CSmsWidget::changePixmap(){
    QString text =textEdit->toPlainText();
    if (text.contains(": )")){

    QImage img(":/images/happy_smilie.png"); // todo: generate image in memory
    m_currentMsg->document()->addResource(QTextDocument::HtmlResource, QUrl("happy_smilie.png" ), img);

    text.replace("","<p><img src=\":/images/happy_smilie.png\"></p>");

    m_currentMsg->setHtml(text);

    }
    }

    This is working once again Thanks


    Added after 6 minutes:


    hi,

    In the above code if i have entered two smiley character like this "hi (first one ) Hope you are fine (second)" .
    In QTextEdit after entering the second smiley first image will get vanished.

    Is it the problem because of both the smilies refers to the same image ?

    Thanks in Advance
    Last edited by sivambigai; 15th November 2010 at 11:02.

  7. #6
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to add smilies in QTextEdit

    You are doing that in most possible wrong way. When you have multiple smileys then strange things will happen.
    Take a look on that (QTextCursor is proper way of modifying editors/QTextDocument content):
    Qt Code:
    1. void CSmsWidget::changePixmap()
    2. {
    3. QRegExp reg(":\\)"); // you can improve regular expression
    4. QTextCursor cursor(textEdit->document()->find(reg));
    5.  
    6. if (!cursor.isNull()) {
    7. cursor.insertHtml("<img src=\":/images/happy_smilie.png\">");
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Sep 2010
    Location
    Chennai
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: how to add smilies in QTextEdit

    hi MarekR22,

    Thanks for your help

  9. #8
    Join Date
    Jul 2017
    Posts
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: how to add smilies in QTextEdit

    Please visit https://youtu.be/QXDfhien_vM

    Please visit https://youtu.be/QXDfhien_vM for Emoticon widget to develop in Qt C++.

Similar Threads

  1. QTextEdit
    By titoaii in forum Newbie
    Replies: 3
    Last Post: 15th April 2010, 10:29
  2. QTextEdit
    By RY in forum Newbie
    Replies: 5
    Last Post: 15th October 2008, 18:52
  3. QTextEdit
    By veda in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2007, 08:30
  4. Replies: 1
    Last Post: 16th February 2007, 08:22
  5. 4.1 to 4.1.1, qtextedit
    By jey in forum Qt Programming
    Replies: 5
    Last Post: 9th March 2006, 13:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.