nspopupbuttoncell attribs
-
Hi,
I've got two questions releated to NSPopUpButtonCell.
In my dataCellForRow: method, I'm trying to set the text color but I'm not
finding a way to do this with an NSPopUpButtonCell like there is for
NSTextFieldCell which uses setTextColor:. How is this done?
Also, in this same method and same control, I'm trying to get rid of the
checkbox that appears when the popup is enabled in order to match the text
alignment of the NSPopUpButtonCell with the other NSTextFieldCell's in the
same column so that they are all left aligned.
- (id) dataCellForRow:(int) row
...
cell = [[NSPopUpButtonCell alloc] init];
[cell setBordered:NO];
[cell setPullsDown:NO];
[cell setFont:[NSFont labelFontOfSize:[NSFont smallSystemFontSize]]];
[cell setControlSize:NSMiniControlSize];
//[cell setAlignment:NSLeftTextAlignment]; no need, default
[cell setEditable:YES];
[cell addItemWithTitle:@"Item A"];
[cell addItemWithTitle:@"Item B"];
[cell setState:NSOffState];
The setState: isn't making the checkbox go away which is my understanding of
what it's for. What am I doing wrong there? -
On 11 æõò 2008, at 6:20 àÃÅ, William Zumwalt wrote:> In my dataCellForRow: method, I'm trying to set the text color but
> I'm not
> finding a way to do this with an NSPopUpButtonCell like there is for
> NSTextFieldCell which uses setTextColor:. How is this done?
I don't think there is a way to do that easily. NSPopUpButtonCell
displays a menu and text in menus should be black. I'm not sure
whether this is specified in the Human Interface Guidelines but even
if it isn't, it is a de facto standard. There may be other indirect
ways to change the color of the menu text, however.> The setState: isn't making the checkbox go away which is my
> understanding of
> what it's for. What am I doing wrong there?
You could change the OnStateImage of each NSMenuItem, so that they
don't have an NSMenuCheckmark image. NSMenuItem has a setOnStateImage:
method. That's the best I could think for now.
Nick -
On Feb 10, 2008, at 8:20 PM, William Zumwalt wrote:> Hi,
>
>
> I've got two questions releated to NSPopUpButtonCell.
>
>
> In my dataCellForRow: method, I'm trying to set the text color but
> I'm not
> finding a way to do this with an NSPopUpButtonCell like there is for
> NSTextFieldCell which uses setTextColor:. How is this done?
Hi William,
To change the text color of an NSPopUpButtonCell, you should set its
menuItem attributed title to a colored string.
Of course, this will also change the color of the menu item in the
menu. If you want the menu item to draw black but the title to draw
blue, you should override -[NSPopUpButtonCell drawTitle: withFrame:
inView:], replace the passed in attributed title to something blue,
and call super with it.> Also, in this same method and same control, I'm trying to get rid...
> of the
> checkbox that appears when the popup is enabled in order to match
> the text
> alignment of the NSPopUpButtonCell with the other NSTextFieldCell's
> in the
> same column so that they are all left aligned.> The setState: isn't making the checkbox go away which is my
> understanding of
> what it's for. What am I doing wrong there?
You lost me here....I think you mean checkmark instead of checkbox,
but even so, the checkmark should not appear in the popup button,
only in its menu. Can you provide a screenshot of what you're seeing?
If you want to remove the checkmark space from the menu, you can use -
[menu setShowsMarkColumn:NO], but be aware that the title in the menu
and in the popup button may no longer line up when the menu is opened.
-Peter -
On 11-Feb-2008, at 13:08 , Peter Ammon wrote:> If you want to remove the checkmark space from the menu, you can use
> -[menu setShowsMarkColumn:NO], but be aware that the title in the
> menu and in the popup button may no longer line up when the menu is
> opened.
It's actually -[menu setShowsStateColumn:NO], added in 10.5.
An earlier thread mentioned this setting, and I couldn't find it in
Interface Builder, so here's how:
You need to select the NSPopUpButton or NSPopUpButtonCell, right click
on it to open a black HUD window, click on the popup on the right side
of the title bar of the HUD window, and select Menu. (Or you can use
one of the other two view modes in the Nib Document Window and select
the menu that way.) With the menu selected, the inspector
(Attributes) has the "Show State Column" checkbox.
--
Steve


