PDA

View Full Version : QTextEdit+resize text on wheel event



gaczm
2nd August 2011, 18:06
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:


class MyTextEdit : public QTextEdit
{
Q_OBJECT

public:
MyTextEdit(QWidget* parent = 0) :
QTextEdit(parent),
fontSize(8)
{
connect(this, SIGNAL(fontSizeChanged(qreal)), this, SLOT(setFontPointSize(qreal)));
}

signals:
void fontSizeChanged(qreal);

protected:
void wheelEvent(QWheelEvent* e)
{
if ((e->modifiers() == Qt::ControlModifier) && (e->delta() > 0))
{
fontSize += 0.5;
emit fontSizeChanged(fontSize);
std::cout << fontSize << " " << fontPointSize () << std::endl;
}
else if ((e->modifiers() == Qt::ControlModifier) && (e->delta() < 0) && (fontSize > 0.5))
{
fontSize -= 0.5;
emit fontSizeChanged(fontSize);
std::cout << fontSize << " " << fontPointSize () << std::endl;
}
else
QTextEdit::wheelEvent(e);
}

private:
qreal fontSize;
};

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

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

Lykurg
2nd August 2011, 18:15
What does not work? Are your if and else are called? Why do you use a custom signal? You can call setFontPointSize directly.

gaczm
2nd August 2011, 18:30
What does not work?
Text is not resizing.

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.