PDA

View Full Version : Transparent TextEdit or Widget



showhand
23rd May 2006, 04:24
Hi, all
I need a transparent widget which could insert some text string on another widget. In fact, just like Photo-Shop, there is a image as background and user can edit text on the image.
Does anybody can tell me how I can do it or give some good advices for me! Thanks!

georgie
23rd May 2006, 04:50
do you mean that the user can select anywhere on the image they want and the text must go there? or is there some fixed place where the text will go and they will just be able to see the image through as the background?

jpn
23rd May 2006, 08:03
Set a totally transparent color for text edit's background.
From QPalette docs (http://doc.trolltech.com/4.1/qpalette.html#details):


QPalette::Base - Used as the background color for text entry widgets; usually white or another light color.




QPalette p = textEdit->palette();
p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
textEdit->setPalette(p);

showhand
24th May 2006, 01:49
do you mean that the user can select anywhere on the image they want and the text must go there? or is there some fixed place where the text will go and they will just be able to see the image through as the background?

As you think, what I want to do is that user can select anywhere on the image they want and instert the text there. Can you give some advices? Thanks a lot!

showhand
24th May 2006, 01:50
Set a totally transparent color for text edit's background.
From QPalette docs (http://doc.trolltech.com/4.1/qpalette.html#details):




QPalette p = textEdit->palette();
p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
textEdit->setPalette(p);


Thank you for your code, I'll try it right now!

georgie
26th May 2006, 01:58
i suspect you would have to subclass QImage and reimplement the mouseClickEvent to initialize a new textEdit where the click was made

georgie
26th May 2006, 05:35
almost-code might be



class MyImage:QImage{
Q_OBJECT
public:
MyImage(...);
protected:
mousePressEvent(QMouseEvent*);
private:
QTextEdit* te;
};

MyImage(..)
{
something;
}

mousePressEvent(QMouseEvent* event)
{
te = new QTextEdit();
//do whatever you do to make it see through
te->move(event->pos());
//i haven't played around but I think you should be able to see the cursor
//and be able to type now
}


Of course I don't know how you want to go about it exactly (1 text edit at a time/more?? editable in the future??) but those things should be easy enough to work out once you get the first one happening I figure :)

munna
26th May 2006, 05:51
class MyImage:QImage{
Q_OBJECT
public:
MyImage(...);
protected:
mousePressEvent(QMouseEvent*);
private:
QTextEdit* te;
};

MyImage(..)
{
something;
}

mousePressEvent(QMouseEvent* event)
{
te = new QTextEdit();
//do whatever you do to make it see through
te->move(event->pos());
//i haven't played around but I think you should be able to see the cursor
//and be able to type now
}


In the above code, every time mouse is pressed a new text edit is created. Where is old text edit ? Where are you deleting it ?

georgie
26th May 2006, 05:58
yer of course, that's why I said that would depend upon what exactly they wanted to do with it...I didn't bother doing more code because the initial qn was not too specific....

once you get one that appears as you want it too, it'd be pretty easy to get new ones and keep track of them....and if it was really like the photoshop way of doing things, where you have to click a button to be able to get the text edit cursor and then when you click a new text edit appears there would have to be some sort of signal from the button setting a flag which turns the new text edit creation on/off....and it would have to deal with the fact that if you clicked again within an already existing text edit you do not want to create a new one but edit the existing one.....

but like i said, none of these parameters were mentioned in the qn so it's hard to know how to deal with any of that stuff ;)