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:
{
Q_OBJECT
public:
fontSize(8)
{
connect(this, SIGNAL(fontSizeChanged(qreal)), this, SLOT(setFontPointSize(qreal)));
}
signals:
void fontSizeChanged(qreal);
protected:
{
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
}
private:
qreal fontSize;
};
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;
};
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
Bookmarks