Results 1 to 3 of 3

Thread: QTextEdit+resize text on wheel event

  1. #1
    Join Date
    Aug 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTextEdit+resize text on wheel event

    I want to have text editor widget that resize text on mouse wheel scroll (like in Qt Creator for example). So I made my class:
    Qt Code:
    1. class MyTextEdit : public QTextEdit
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MyTextEdit(QWidget* parent = 0) :
    7. QTextEdit(parent),
    8. fontSize(8)
    9. {
    10. connect(this, SIGNAL(fontSizeChanged(qreal)), this, SLOT(setFontPointSize(qreal)));
    11. }
    12.  
    13. signals:
    14. void fontSizeChanged(qreal);
    15.  
    16. protected:
    17. void wheelEvent(QWheelEvent* e)
    18. {
    19. if ((e->modifiers() == Qt::ControlModifier) && (e->delta() > 0))
    20. {
    21. fontSize += 0.5;
    22. emit fontSizeChanged(fontSize);
    23. std::cout << fontSize << " " << fontPointSize () << std::endl;
    24. }
    25. else if ((e->modifiers() == Qt::ControlModifier) && (e->delta() < 0) && (fontSize > 0.5))
    26. {
    27. fontSize -= 0.5;
    28. emit fontSizeChanged(fontSize);
    29. std::cout << fontSize << " " << fontPointSize () << std::endl;
    30. }
    31. else
    32. QTextEdit::wheelEvent(e);
    33. }
    34.  
    35. private:
    36. qreal fontSize;
    37. };
    To copy to clipboard, switch view to plain text mode 

    But it don't work. Can anyone help? :-)

    ---
    Sorry for bad english, hope it is understandable

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QTextEdit+resize text on wheel event

    What does not work? Are your if and else are called? Why do you use a custom signal? You can call setFontPointSize directly.

  3. #3
    Join Date
    Aug 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTextEdit+resize text on wheel event

    Quote Originally Posted by Lykurg View Post
    What does not work?
    Text is not resizing.
    Quote Originally Posted by Lykurg View Post
    Why do you use a custom signal? You can call setFontPointSize directly.
    Well, I tried but it also don't works.

    It is little weird for me, becouse when i call setFontPointSize function in constructor for example it works, but when i call it in wheelEvent function it don't.

Similar Threads

  1. QGLWidget and wheel event
    By shenakan in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 15:21
  2. resize event
    By wirasto in forum Qt Programming
    Replies: 6
    Last Post: 16th July 2009, 10:01
  3. wheel event problem
    By bhogasena in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 19:11
  4. resize QTextEdit
    By maartenS in forum Newbie
    Replies: 8
    Last Post: 22nd September 2008, 22:02
  5. Resize event
    By boss_bhat in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2006, 15:43

Tags for this Thread

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.