Results 1 to 14 of 14

Thread: CSS Issue with QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default CSS Issue with QTextEdit

    Hello,

    I have followed the document from http://doc.qtsoftware.com/4.5/richtext-html-subset.html to set some css style when declaring an html string that will later on be used in a QTextEdit widget.

    Some of the css style are working, while others have not effect.
    In my example:
    background is working
    color is working
    align is NOT working
    font-size is NOT working

    Did I miss something?

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QString html_sequence = QString(" \
    7. <html> \
    8. <head> \
    9. <style type=text/css> \
    10. body { background: #ffffff; color: black; } \
    11. .title { background: #f0f0f0; align: center; } \
    12. .subtitle { font-size: 8px; color: red;} \
    13. .small-subtitle { font-size: 6px; color: blue; } \
    14. </style> \
    15. </head> \
    16. \
    17. <body> \
    18. <h1 class=title>Title without subtitle<br /></h1> \
    19. <h1 class=title>Title with subtitle<br /><span class=subtitle>This is the subtitle</span></h1> \
    20. <h1 class=title>Title with small subtitle<br /><span class=small-subtitle>This is the small subtitle</span></h1> \
    21. </body> \
    22. </html> \
    23. ");
    24.  
    25. QTextEdit test(html_sequence);
    26. test.show();
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: CSS Issue with QTextEdit

    can u give the string in one line?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: CSS Issue with QTextEdit

    Does it change anything if you set the attributes with style="..." attribute to specified tags instead of using the <style> tag?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    MrDeath, I used the backslahes in order to make the html string more readable.
    Wasota, I will try your suggestion, but why is it working for some attributes and why is it not working for some other ?

  5. #5
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    Could this simply be a bug in QT4.5 ?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: CSS Issue with QTextEdit

    Quote Originally Posted by schall_l View Post
    Could this simply be a bug in QT4.5 ?
    No. It works fine for me.

    html Code:
    1. <p style="font-size:36pt;">BLA</p>
    2. <p align="center">XYZ</p>
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    why are:

    .title { background: #f0f0f0; text-decoration: underline; }
    .title { color: red; }
    .title { font-size:large;}

    working and

    .title { align: center; }
    .title { font-size:8px; }

    not working ?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: CSS Issue with QTextEdit

    Try pt instead of px.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    No no no, I've tried this before.

    I am still thinking that this could be a bug in Qt as some of the attributes from http://doc.qtsoftware.com/4.5/richtext-html-subset.html will work and some will not work.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: CSS Issue with QTextEdit

    Yes, it's always easiest to blame someone else but still using pt instead of px did work for me
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    This is the code using pt instead of px and the attached screenshot.
    As you can see some of the attributes are interpreted correctly, some not.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QString html_sequence = QString(" \
    7. <html> \
    8. <head> \
    9. <style type=text/css> \
    10. body { background: #ffffff; color: black; } \
    11. .title { background: #f0f0f0; align: center; } \
    12. .subtitle { font-size: 8pt; color: red;} \
    13. .small-subtitle { font-size: 6pt; color: blue; } \
    14. </style> \
    15. </head> \
    16. \
    17. <body> \
    18. <h1 class=title>Title without subtitle<br></h1> \
    19. <h1 class=title>Title with subtitle<br><span class=subtitle>This is the subtitle</span></h1> \
    20. <h1 class=title>Title with small subtitle<br><span class=small-subtitle>This is the small subtitle</span></h1> \
    21. </body> \
    22. </html> \
    23. ");
    24.  
    25. QTextEdit test(html_sequence);
    26. test.show();
    27. return app.exec();
    28. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  12. #12
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: CSS Issue with QTextEdit

    Could it be that there is some priority relevant issues ?
    Could possibly <h1> be evaluated with a higher priority then the font-size attribute from subtitle and small-subtitle ?
    What's about the priority of align: center ?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: CSS Issue with QTextEdit

    html Code:
    1. <html>
    2. <head>
    3. <style type=text/css>
    4. body { background: #ffffff; color: black; }
    5. .title { background: #f0f0f0; }
    6. .subtitle { font: 8pt; color: red;}
    7. .small-subtitle { font: 6pt; color: blue; }
    8. </style>
    9. </head>
    10.  
    11. <body>
    12. <h1 align="center" class=title>Title without subtitle<br></h1>
    13. <h1 align="center" class=title>Title with subtitle<br><span class=subtitle>This is the subtitle</span></h1>
    14. <h1 align="center" class=title>Title with small subtitle<br><span class=small-subtitle>This is the small subtitle</span></h1>
    15. </body>
    To copy to clipboard, switch view to plain text mode 

    I can't get "font-size" to work with pt or px, it works otherwise.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTextEdit Performance handling large paragraphs
    By netuno in forum Qt Programming
    Replies: 14
    Last Post: 1st September 2010, 22:58
  2. Drawing on QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2009, 09:40
  3. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  4. QTextEdit issue
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2006, 09:07
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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
  •  
Qt is a trademark of The Qt Company.