Results 1 to 9 of 9

Thread: Transparent TextEdit or Widget

  1. #1
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Transparent TextEdit or Widget

    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!
    There is no secret in the face of the code.

  2. #2
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent TextEdit or Widget

    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?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Transparent TextEdit or Widget

    Set a totally transparent color for text edit's background.
    From QPalette docs:
    QPalette::Base - Used as the background color for text entry widgets; usually white or another light color.
    Qt Code:
    1. QPalette p = textEdit->palette();
    2. p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
    3. textEdit->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Transparent TextEdit or Widget

    Quote Originally Posted by georgie
    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!
    There is no secret in the face of the code.

  5. #5
    Join Date
    Jan 2006
    Posts
    26
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: Transparent TextEdit or Widget

    Quote Originally Posted by jpn
    Set a totally transparent color for text edit's background.
    From QPalette docs:


    Qt Code:
    1. QPalette p = textEdit->palette();
    2. p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
    3. textEdit->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    Thank you for your code, I'll try it right now!
    There is no secret in the face of the code.

  6. #6
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent TextEdit or Widget

    i suspect you would have to subclass QImage and reimplement the mouseClickEvent to initialize a new textEdit where the click was made
    perfection is an illusion which is stopping me from starting now and finishing on time

  7. #7
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent TextEdit or Widget

    almost-code might be

    Qt Code:
    1. class MyImage:QImage{
    2. Q_OBJECT
    3. public:
    4. MyImage(...);
    5. protected:
    6. mousePressEvent(QMouseEvent*);
    7. private:
    8. QTextEdit* te;
    9. };
    10.  
    11. MyImage(..)
    12. {
    13. something;
    14. }
    15.  
    16. mousePressEvent(QMouseEvent* event)
    17. {
    18. te = new QTextEdit();
    19. //do whatever you do to make it see through
    20. te->move(event->pos());
    21. //i haven't played around but I think you should be able to see the cursor
    22. //and be able to type now
    23. }
    To copy to clipboard, switch view to plain text mode 

    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
    perfection is an illusion which is stopping me from starting now and finishing on time

  8. #8
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent TextEdit or Widget

    Qt Code:
    1. class MyImage:QImage{
    2. Q_OBJECT
    3. public:
    4. MyImage(...);
    5. protected:
    6. mousePressEvent(QMouseEvent*);
    7. private:
    8. QTextEdit* te;
    9. };
    10.  
    11. MyImage(..)
    12. {
    13. something;
    14. }
    15.  
    16. mousePressEvent(QMouseEvent* event)
    17. {
    18. te = new QTextEdit();
    19. //do whatever you do to make it see through
    20. te->move(event->pos());
    21. //i haven't played around but I think you should be able to see the cursor
    22. //and be able to type now
    23. }
    To copy to clipboard, switch view to plain text mode 

    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 ?

  9. #9
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Transparent TextEdit or Widget

    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
    perfection is an illusion which is stopping me from starting now and finishing on time

Similar Threads

  1. minimize child widget
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2006, 13:02
  2. Replies: 4
    Last Post: 24th March 2006, 23:50
  3. transparent widget
    By hijinks in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2006, 10:43
  4. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16
  5. advanced split widget
    By vitaly in forum Qt Programming
    Replies: 10
    Last Post: 24th January 2006, 21:00

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.