PDA

View Full Version : How to make QTextEdit to look like QLabel?



pielas
6th April 2010, 17:27
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?

Lykurg
6th April 2010, 17:38
See QTextEdit::textInteractionFlags and QWidget::setBackgroundRole() or QWidget::palette.

pielas
6th April 2010, 18:04
textInteractionFlags works but I've tried every ColorRole and nothing has changed with background under text.

borisbn
6th April 2010, 19:22
Is it a theoretical question or practical? If the last - just use QLabel ...

pielas
6th April 2010, 19:30
It's practical question. I would use QLabel but QTextEdit have built-in scroll bars and I want to use them.

borisbn
6th April 2010, 19:45
Use QScrollArea with QLabel inside it

Lykurg
6th April 2010, 21:20
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.

wysota
6th April 2010, 21:37
I would also advise to use QTextBrowser instead of QTextEdit if you only want to display something.

Lykurg
7th April 2010, 07:40
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?

wysota
7th April 2010, 07:46
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.

Lykurg
7th April 2010, 08:31
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.

pielas
8th April 2010, 06:01
I couldn't change this background to other than black or white so I decided to use QScrollArea with QLabel. Thanks for replies.

wysota
8th April 2010, 08:02
I don't have any problems with changing the background colour of QTextEdit...

pielas
8th April 2010, 13:53
What option do you use to set that? My edit still looks like that:
http://img213.imageshack.us/img213/5048/examplejv.png (http://img213.imageshack.us/i/examplejv.png/)

wysota
8th April 2010, 14:03
Mine looks like this:

4492

pielas
8th April 2010, 14:33
It's probably something wrong with my system becouse your form in KUIViewer looks like this:
http://img547.imageshack.us/img547/4171/example2.png (http://img547.imageshack.us/i/example2.png/)

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

//edit2: Yeah it works. I've wrotten this:
QPalette palette = edit->palette();
palette.setColor(QPalette::Base, palette.color(QPalette::Window));
edit->setPalette(palette);

wysota
8th April 2010, 14:59
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.

pielas
8th April 2010, 15:36
Yes it works too and It's probably better way than mine. Thanks everybody for help.