The following works for me. I only typed "a" as shown (no spaces or tabs), and that's worked for me on both X11 and (IIRC) Windows. Of course you'll still have to unhighlight the line when the current line changes, but this just shows it should be possible to do.

editor.h
#ifndef EDITOR_H
#define EDITOR_H
#include <QTextEdit>
{
Q_OBJECT
public:
explicit Editor
(QWidget *parent
= 0);
private slots:
void highlightCurrentLine();
};
#endif // EDITOR_H
#ifndef EDITOR_H
#define EDITOR_H
#include <QTextEdit>
class Editor : public QTextEdit
{
Q_OBJECT
public:
explicit Editor(QWidget *parent = 0);
private slots:
void highlightCurrentLine();
};
#endif // EDITOR_H
To copy to clipboard, switch view to plain text mode
editor.cpp
#include <QtGui>
#include "editor.h"
{
connect(this, SIGNAL(cursorPositionChanged()),
this, SLOT(highlightCurrentLine()));
}
void
Editor::highlightCurrentLine()
{
format.setBackground(palette().alternateBase());
cursor.setBlockFormat(format);
}
#include <QtGui>
#include "editor.h"
Editor::Editor(QWidget *parent):
QTextEdit(parent)
{
connect(this, SIGNAL(cursorPositionChanged()),
this, SLOT(highlightCurrentLine()));
}
void
Editor::highlightCurrentLine()
{
QTextCursor cursor = textCursor();
QTextBlock block = cursor.block();
QTextBlockFormat format = block.blockFormat();
format.setBackground(palette().alternateBase());
cursor.setBlockFormat(format);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include "editor.h"
#include <QtGui>
int
main(int argc, char *argv[])
{
Editor editor;
editor.show();
return app.exec();
}
#include "editor.h"
#include <QtGui>
int
main(int argc, char *argv[])
{
QApplication app(argc, argv);
Editor editor;
editor.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks