Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > TextView with transparent background?

TextView with transparent background?
Thread Tools
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 21, 2002, 01:00 AM
 
Hello ...


I want my NSTextView to have a transparent background. I've tried assigning a zero-percent-opacity color to the background in IB, and I've tried sending "setDrawsBackground:NO" to the view programmatically. No matter what I do, the text view's background displays window-striping, but the placement of the view makes the stripes out of phase with the window's own stripes, which is just ugly.

I note that in IB, the stripes are perfectly aligned and the background is wonderfully transparent. When the program runs, the stripes get mis-aligned. (Even when the stripes are aligned, I can still --but just barely-- perceive the view's rectangle.)

How do I get an honest-to-goodness *not-visible* background in a NSTextView?


Thanks and regards,

DayLate Don
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Apr 21, 2002, 03:33 AM
 
Hmm... perhaps you need to subclass NSTextView, NSScrollView, or NSClipView and override <font face = "courier">isOpaque</font> to return NO. Dunno if it'll work...
Rick Roe
icons.cx | weblog
     
Forum Regular
Join Date: Mar 2000
Status: Offline
Reply With Quote
Apr 21, 2002, 04:01 AM
 
you need to setup the window and the views. something like this should do it:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>//Set the background color to clear</font>
[[self window] setBackgroundColor: [NSColor clearColor]];

<font color = brown>//set the transparency close to one.</font>
[[self window] setAlphaValue: <font color = blue>0.9999</font>];

[[self window] setOpaque: NO];


[scrollView setDrawsBackground: NO];

[textView setDrawsBackground: NO];

</font>[/code]
     
Forum Regular
Join Date: Mar 2000
Status: Offline
Reply With Quote
Apr 21, 2002, 04:02 AM
 
&lt;error&gt;

[ 04-21-2002: Message edited by: nibs ]
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 26, 2002, 07:37 AM
 
Hello ...

I found the trouble. I have to send "setDrawsBackground:NO" to the NSScrollView containing the NSTextView.

That is sending
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[[myTextView superview] superview] setDrawsBackground:NO];
</font>[/code]
does the trick. ( [myTextView superview] is the NSClipView; the second 'superview' gets me out to the NSScrollView level.)

It turns out that I have to send this to every scrolly object in my app (for instance a scrolling matrix of buttons). Hopefully Apple will provide a "Draws Background" checkbox to the NSScrollView info palette in Interface Builder. (And the same checkbox for NSTextView, which passes its value up to the scroll view.) The double-superview call raises (now numerous) Project Builder warnings that NSView doesn't understand "setDrawsBackground:".

Is there a way to tell Project Builder not to throw out that warning each time?


Thanks,

DayLateDon
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 26, 2002, 12:14 PM
 
Originally posted by DayLateDon:
<STRONG>Is there a way to tell Project Builder not to throw out that warning each time?


Thanks,

DayLateDon</STRONG>
Cast it to the appropriate type as so:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
[(NSScrollView*)[myTextView superview] superview] setDrawsBackground:NO];
</font>[/code]

HTH,
F-bacher
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Apr 27, 2002, 01:23 AM
 
Hello ...


"Cast it to the appropriate type" ... Of course!

(slaps self on forehead)


Thanks ...

DayLateDon
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:50 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2