View Full Version : Contest

25th January 2006, 08:44
Sorry but has there's no Contests section in the forum I decided to post it here!

I would like to start a contest( nothing to gain except fame :D ) :
Anybody able to make a fast QTextEdit whose each line can be fully colored (I mean the background coloration doesn't stop after last letter)
In addition this widget would need to implement a working find and replace dialog.

Anyone interested???

edit: forgot to told you about the folding/unfolding abilities
have fun!

28th January 2006, 01:14
Anybody able to make a fast QTextEdit whose each line can be fully colored (I mean the background coloration doesn't stop after last letter)
I think you can do what you want with QTextBlockFormat::setBackground(const QBrush &).

28th January 2006, 20:39
I already use the TextBlockFormat but I didn't find any way to make it color after the last character. Any hint/workaround will be welcomed :(

29th January 2006, 01:02
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.



#ifndef EDITOR_H
#define EDITOR_H

#include <QTextEdit>

class Editor : public QTextEdit

explicit Editor(QWidget *parent = 0);
private slots:
void highlightCurrentLine();
#endif // EDITOR_H


#include <QtGui>
#include "editor.h"

Editor::Editor(QWidget *parent):
connect(this, SIGNAL(cursorPositionChanged()),
this, SLOT(highlightCurrentLine()));

QTextCursor cursor = textCursor();
QTextBlock block = cursor.block();
QTextBlockFormat format = block.blockFormat();


#include "editor.h"
#include <QtGui>

main(int argc, char *argv[])
QApplication app(argc, argv);
Editor editor;
return app.exec();

30th January 2006, 09:21
nice! Thanks for your help, I'll try it. :D

edit : :(

Tried it and it didn't work! Quite confusing!!! Which version of Qt are you using???
I already used that method to set the backgroud but with a QColor instead (which was actually converted to a QBrush implicitly...)

I think I'll start a thread on that subject in the Qt programming section, it may bring a solution...

1st February 2006, 00:19
Which version of Qt are you using???
Qt 4.1.0. If you're using a different version and it doesn't work, then I might consider that a bug or at least lack of documentation specifying the correct behaviour. But if you're using the same version, then that's pretty weird.

1st February 2006, 08:39
I'm using a 4.1.1 snapshot but anyway I doubt it comes from that. Did you try your program under M$ Win??

1st February 2006, 13:48
I re-verified that it worked on Windows XP yesterday. Same version of Qt, 4.1.0.
I'll try the latest snapshot soon, since at this point it looks as if that's what the reason is.

1st February 2006, 20:34
:eek: Thinking to something: do you use word wrap??? I think it's the default setting. My editor doesn't wrap anything so it may come from that!

I'll try it tomorrow!

edit : sorry posted it twice, damn buggy computer!!! And no way deleting posts!!!:rolleyes:

2nd February 2006, 00:32
Ah, wordwrap was the reason. I thought you'd tried the code I posted as is and it didn't work. Anyway, I'm about to post something that should work in the " Rich Text Tale Vol1 : Background colors" thread.