I am using fyne. I am working on a game (with buttons obviously). I would like to know if there is a way to change button's background? I know there is button with image instead of text, but I would only like to change background color of button.
The Fyne widget APIs are based on meaning rather than graphics, which makes two potential answers.
You can mark a button as high importance (Button.Importance = widget.HighImportance) which will show as a primary colour.
If your application wishes to control colour then the way you do it is to place a background rectangle under the button, which will show through (e.g. as container.NewMax(canvas.NewRectangle(bgColor), button)).
Related
I am a rookie Cocoa guy. I need to design and implement a view which will show collection of labels on Mac OS using Xamarin. These labels will have a text and color associated with them. When shown inside the view, label should expand till it covers whole text and it will be shown with background and foreground colors.
I have attached the picture of this user control on Windows, you can see that labels inside the StackPanel are expanding till they cover the whole text. Hope this gives better idea about my ask.
The $64,000 question is "are these labels controls?" In other words, do you expect the user to click on these to do something, or are they just for display?
If your answer is "just for display", the solution is super simple: Use an NSTextField and programmatically add attributed text (NSAttributedString) to it. Attributed text attaches display properties to runs of text within the field; properties like "background color".
If you want these to be buttons that you can click on, then things get a lot more complicated.
Since you apparently want the button layout to "flow", you might look into imbedding buttons (well, button cells) into an NSTextField using attachments. This is normally how non-text content (say, an image) can be inserted, but with some fiddling it can actually be anything a control cell can draw. See How to insert a NSButton into a NSTextView? (inline).
Warning: this is not a "rookie" topic and will involve control cells and custom event handling.
If I were doing this, I'd probably just create NSButton objects for each label (choosing an appropriate style/look like NSRecessedBezelStyle), create a custom subclass of NSView to contain them, and then override the layout method to position all of the buttons the way I want.
To be thorough, I'd also override the intrinsic size methods so the whole thing could participate in auto-layout, based on the number and size of buttons it contained.
I Want to write a text message, typically "Drag & Drop a PDF here" on PDFView's "background" view. By background view I mean the matte gray view displayed when no PDF document is set.
Based on documentation, I was only able to change the background color (default is gray) using
(void)setBackgroundColor:(NSColor *)newColor
Any idea how to implement this?
Thanks in advance.
Based on Willeke answer, I was able to put a label on top on my PDF view using the Z indexes.
In interface builder, the lower the item in the list, the higher the z index.
Thus in my example, I dragged and dropped the label under the PDFView.
Note: you need to launch the application to see the result, the preview will not show the label.
If I subclass QLabel and I add a QLabel directly to my QDialog, it works fine. If I add this label inside a ScrollArea, the thing I’m drawing doesn’t show unless I resize the dialog itself. Yes, weird.
I’ve setup compilable example code that indicates what the problem is. What I am trying to do is to select an area of an image with my mouse, by drawing a rectangle on the corresponding area. The images my program is designed to work with can be very large, and thus, I need to have a scroll area so as the dialog to stay at a logical dimension, and not to fill the entire screen (or even multiple workspaces, if we are talking about a linux machine with multiple desktops).
Everything works fine, except that the drawing (selection-rectangle) isn’t visible unless the dialog is resized – manually. I think I have to update something while drawing, but I’m not sure what. Well, here’s the example code: http://paste.ubuntu.com/1151553/
Another issues that I don’t know how to solve (and I want your suggestions there) are (1) when the user is selecting an area, how to set it to automatically scroll when the user actually selects an area by pushing against to a wall of the scroll area (I guess I am understandable here). (2) is there a way to let the user select a rectangle and then, when he left-clicks on a position with holding down the [Shift] button, the bottom right edge of his previous selection to actually go through the point he clicks at?
The documentation indicates that you have to set a Layout somehow somewhere, but I'm not sure how to do this to my occassion.
Thanks in advance for any help.
about problem (1):
just use of Event. i think mouse Enter Event or Leave Event is good for that.
and to do that i think you can use a hidden rectangular that fill the whole of the screen.
and over write the mouse leave Event for that rectangular and tell in that function , to scroll the page.
I am tryimng to make a UI. But in qt, the window size is too short, I want to work in a separate windows like photoshop. Here I am posting the picture. I want to see the middle window(i rounded it by rose color) in full screen size. Can anybody help me?
EDIT:
If I want to create a full screen application, How can I position the widgets in it. It's possible dragging a widget inside a scroll bared window,but is not user friendly. I want it to work like photoshop, like separate windows.
If you want to have more space to work on the design of your widgets, you can open QtDesigner separately and maximize the design area. Panels can be closed and undocked.
Now if you want to maximized only the central widget, there is a trick:
Create a custom widget and work on it in QtDesigner. You will be able to put it in near full screen by increasing its size
Set your custom widget as central widget in your GUI application.
Previous answer before edit:
Hi, If you want to view your widget in fullsreen mode, you can call the ShowFullScreen function. If what you want is to maximize the widget, you can call the ShowMaximized function.
How can I add text on top of a NSLevelIndicator? [the NSLevelIndicator is in my statusbar, if that matters]
The best way to add text to your NSLevelIndicator user interface is by adding a separate Label NSTextField. The NSLevelIndicator control does not have a title or other text associated with it.
From within Interface Builder, just grab a Label and drag it to your window above or beside the NSLevelIndicator.
Contrary to the correct answer to your previous question, if you want to use an NSLevelIndicator as a background and draw text on top of it, you're better off creating a custom view that owns and uses an NSLevelIndicatorCell for the background drawing.
You might also consider drawing the background yourself; e.g., fill with your choice of green/yellow/red, and then draw a white gradient on top of it. This is more appropriate if you're not really indicating a level with your level indicator.
Also, don't forget to test your application with Sim Daltonism, to make sure that the text is still readable to color-blind users.