Results 1 to 18 of 18

Thread: How to make QTextEdit to look like QLabel?

  1. #1
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to make QTextEdit to look like QLabel?

    Hi, how to make QTextEdit to look like QLabel? I mean to disable text selection, hide borders and set background like QMainWindow background. I've tried to set flags QFrame::StyledPanel and QFrame::Plain but background hasn't changed(remained white). So what should I do to do that?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to make QTextEdit to look like QLabel?


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

    pielas (8th April 2010), soulless (9th April 2010)

  4. #3
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    textInteractionFlags works but I've tried every ColorRole and nothing has changed with background under text.

  5. #4
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make QTextEdit to look like QLabel?

    Is it a theoretical question or practical? If the last - just use QLabel ...

  6. #5
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    It's practical question. I would use QLabel but QTextEdit have built-in scroll bars and I want to use them.

  7. #6
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make QTextEdit to look like QLabel?

    Use QScrollArea with QLabel inside it

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

    pielas (8th April 2010)

  9. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to make QTextEdit to look like QLabel?

    Quote Originally Posted by pielas View Post
    but I've tried every ColorRole and nothing has changed with background under text.
    Well I don't know how your roles for your widget are defines. So did you try to use the widgets palette with Qt::transparent? And also play with QWidget::autoFillBackground.

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

    Default Re: How to make QTextEdit to look like QLabel?

    I would also advise to use QTextBrowser instead of QTextEdit if you only want to display something.
    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. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to make QTextEdit to look like QLabel?

    Quote Originally Posted by wysota View Post
    I would also advise to use QTextBrowser instead of QTextEdit if you only want to display something.
    What are the reasons for choosing QTextBrowser? It inherits QTextEdit and if you only want to display something, QTextEdit with QTextEdit::setReadOnly() should be the lightest class to do so? (Without hyperlinks). Or do I miss something?

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

    Default Re: How to make QTextEdit to look like QLabel?

    Quote Originally Posted by Lykurg View Post
    What are the reasons for choosing QTextBrowser? It inherits QTextEdit and if you only want to display something, QTextEdit with QTextEdit::setReadOnly() should be the lightest class to do so? (Without hyperlinks). Or do I miss something?
    No, in general you are right. But QTextBrowser would be a direct equivalent of QLabel in the text document world including the hyperlinks which are available in QLabel as well. If one doesn't need hyperlinks then indeed QTextEdit will be a bit lighter.
    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.


  13. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to make QTextEdit to look like QLabel?

    Quote Originally Posted by wysota View Post
    But QTextBrowser would be a direct equivalent of QLabel in the text document world including the hyperlinks which are available in QLabel as well.
    Ah, ok, I see.

  14. #12
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    I couldn't change this background to other than black or white so I decided to use QScrollArea with QLabel. Thanks for replies.

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

    Default Re: How to make QTextEdit to look like QLabel?

    I don't have any problems with changing the background colour of QTextEdit...

  16. #14
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    What option do you use to set that? My edit still looks like that:

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

    Default Re: How to make QTextEdit to look like QLabel?

    Mine looks like this:

    preview..png
    Attached Files Attached Files

  18. #16
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    It's probably something wrong with my system becouse your form in KUIViewer looks like this:


    //edit: oh it's my fault I haven't seen that this is fixed background color.

    //edit2: Yeah it works. I've wrotten this:
    Qt Code:
    1. QPalette palette = edit->palette();
    2. palette.setColor(QPalette::Base, palette.color(QPalette::Window));
    3. edit->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 
    Last edited by pielas; 8th April 2010 at 14:52.

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

    Default Re: How to make QTextEdit to look like QLabel?

    You can probably use the transparent colour as well. That's what I wanted to do myself but I couldn't see a way to express it in Designer and I didn't want to do any manual coding.

  20. #18
    Join Date
    Apr 2010
    Location
    Poland
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make QTextEdit to look like QLabel?

    Yes it works too and It's probably better way than mine. Thanks everybody for help.

Similar Threads

  1. QTextEdit. To make selected text as Bold.
    By KIBSOFT in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2016, 10:47
  2. Replies: 1
    Last Post: 29th September 2009, 19:44
  3. Replies: 5
    Last Post: 17th July 2008, 13:12
  4. Replies: 13
    Last Post: 18th February 2008, 00:20
  5. Replies: 3
    Last Post: 20th November 2007, 07: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.