Results 1 to 10 of 10

Thread: Contest

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Contest

    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 ) :
    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!
    Last edited by fullmetalcoder; 25th January 2006 at 21:53.
    Current Qt projects : QCodeEdit, RotiDeCode

  2. The following 2 users say thank you to fullmetalcoder for this useful post:


  3. #2
    Join Date
    Jan 2006
    Posts
    11
    Thanked 5 Times in 5 Posts

    Default Re: Contest

    Quote Originally Posted by fullmetalcoder
    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 &).
    Last edited by blockd; 28th January 2006 at 02:23.

  4. The following user says thank you to blockd for this useful post:


  5. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Contest

    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
    Current Qt projects : QCodeEdit, RotiDeCode

  6. The following user says thank you to fullmetalcoder for this useful post:


  7. #4
    Join Date
    Jan 2006
    Posts
    11
    Thanked 5 Times in 5 Posts

    Default Re: Contest

    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
    Qt Code:
    1. #ifndef EDITOR_H
    2. #define EDITOR_H
    3.  
    4. #include <QTextEdit>
    5.  
    6. class Editor : public QTextEdit
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. explicit Editor(QWidget *parent = 0);
    12. private slots:
    13. void highlightCurrentLine();
    14. };
    15. #endif // EDITOR_H
    To copy to clipboard, switch view to plain text mode 

    editor.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "editor.h"
    3.  
    4. Editor::Editor(QWidget *parent):
    5. QTextEdit(parent)
    6. {
    7. connect(this, SIGNAL(cursorPositionChanged()),
    8. this, SLOT(highlightCurrentLine()));
    9. }
    10.  
    11. void
    12. Editor::highlightCurrentLine()
    13. {
    14. QTextCursor cursor = textCursor();
    15. QTextBlock block = cursor.block();
    16. QTextBlockFormat format = block.blockFormat();
    17. format.setBackground(palette().alternateBase());
    18. cursor.setBlockFormat(format);
    19. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "editor.h"
    2. #include <QtGui>
    3.  
    4. int
    5. main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. Editor editor;
    9. editor.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by blockd; 29th January 2006 at 02:07.

  8. The following user says thank you to blockd for this useful post:


  9. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Contest

    nice! Thanks for your help, I'll try it.

    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...
    Last edited by fullmetalcoder; 30th January 2006 at 17:09.
    Current Qt projects : QCodeEdit, RotiDeCode

  10. The following user says thank you to fullmetalcoder for this useful post:


  11. #6
    Join Date
    Jan 2006
    Posts
    11
    Thanked 5 Times in 5 Posts

    Default Re: Contest

    Quote Originally Posted by fullmetalcoder
    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.

  12. The following user says thank you to blockd for this useful post:


  13. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Contest

    I'm using a 4.1.1 snapshot but anyway I doubt it comes from that. Did you try your program under M$ Win??
    Current Qt projects : QCodeEdit, RotiDeCode

  14. The following user says thank you to fullmetalcoder for this useful post:


  15. #8
    Join Date
    Jan 2006
    Posts
    11
    Thanked 5 Times in 5 Posts

    Default Re: Contest

    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.

  16. The following user says thank you to blockd for this useful post:


  17. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Contest

    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!!!
    Current Qt projects : QCodeEdit, RotiDeCode

  18. The following user says thank you to fullmetalcoder for this useful post:


  19. #10
    Join Date
    Jan 2006
    Posts
    11
    Thanked 5 Times in 5 Posts

    Default Re: Contest

    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.

  20. The following user says thank you to blockd for this useful post:


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.