drawrect

Qt drawRect in background

筅森魡賤 提交于 2019-12-06 04:13:19
问题 I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider void paintEvent(QPaintEvent *e) { QPainter painter(this); painter.begin(this); painter.setBrush(/*not important*/); // This covers up the control. How do I make it so the color is in // the background and the control is still visible? painter.drawRect(rect()); painter.end(); } 回答1: To set the background of a widget you could set the style sheet: theSlider

How can I fill a rect with an alpha color using CoreGraphics?

穿精又带淫゛_ 提交于 2019-12-06 03:49:52
问题 In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this: [[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); The problem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks in advance! 回答1: Use CGContextSetBlendMode() before you draw the rect. 回答2: Set your view background color to transparent… It should work. 来源: https:/

UIView draw rect retain's the previous drawing and does not clear on view.transform

孤街醉人 提交于 2019-12-06 03:12:25
问题 I have the following code to show marker in a UIView. The marker show's well, and once we try to pinch zoom and scale the UIView using the transform the first drawing remains as it is, even after calling setNeedsDisplay. My Custom UIView subclass has the following code - (void)drawRect:(CGRect)rect { // Drawing code CGFloat w=20.0f; CGFloat h=8.0f; CGContextRef context=UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); CGContextClearRect

UIView overriding drawRect causes view not to obey masksToBounds

心不动则不痛 提交于 2019-12-06 00:42:08
问题 I am trying to override the drawRect: method of UIView in my custom view. However, my view has a border radius defined as: sub = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:self options:nil] objectAtIndex:0]; [self addSubview:sub]; [sub setUserInteractionEnabled:YES]; [self setUserInteractionEnabled:YES]; CALayer *layer = sub.layer; layer.masksToBounds = YES; layer.borderWidth = 5.0; layer.borderColor = [UIColor whiteColor].CGColor; layer.cornerRadius = 30.0; This works

setNeedsDisplay does not trigger drawRect in subviews as expected

冷暖自知 提交于 2019-12-05 09:11:28
I'm struggling with setNeedsDisplay . I thought it was supposed to trigger calls of drawRect: for the view for which it is called and the hierarchy below that if it's within the view's bounds, but I'm not finding that to be the case. Here is my setup: From the application delegate, I create a view whose size is a square that covers essentially the whole screen real estate. This view is called TrollCalendarView . There is not much that happens with TrollCalendarView except for a rotation triggered by the compass. There are 7 subviews of TrollCalendarView called PlatformView intended to contain

iOS 6 view hierarchy nightmare

我的梦境 提交于 2019-12-05 08:32:59
I have an app in the app store with nearly 5-star rating, but when iOS 6 came out, some of the views in in the app's main view hierarchy started blinking. This happens on the app that was in the store (I removed it when iOS6 came out) as well as in the simulator. I've spent about 14 hours, trying 100 things, to debug this in Xcode, but can't get any traction on it. Subviews disappear and reappear like there's a gremlin randomly setting the visible property off and on for each of them up to 10 times per second, in between longer periods where everything is normal. The main interface is a dial

CADisplayLink and drawRect

ぃ、小莉子 提交于 2019-12-05 08:01:23
I need help to better understand how CADisplayLink and drawRect behave, so that I can figure out how to keep my app's framerate at a smooth 60fps. My (presumably incorrect) understanding so far is the following: 1) CADisplayLink calls a specified selector when the display refreshes (a so-called "v-sync" event; about every 16ms). 2) iOS uses double buffering, meaning that while one frame buffer is being displayed we can prepare (draw to) the other, and the two are swapped at the next v-sync event. 3) Therefore, from the time the display link fires, I have about 16ms to ensure that all

Dynamically redraw re sized circle in iPhone

流过昼夜 提交于 2019-12-05 07:05:36
问题 What im trying to do is have a user touch the screen, when the touch is detected at the position the circle is meant to grow in size (and keep growing) until the user lets go. I know how to detect touches but the problem im having is trying to draw and have the circle re drawn as its getting larger. What is the best way to do this? 回答1: I would use a combination of UILongPressGestureRecognizer , NSTimer , and UIBezierPath to achieve this. First, set up your viewDidLoad to add and configure

asynchronous drawing and touches

放肆的年华 提交于 2019-12-05 04:33:54
问题 I have a draw area (UIView), where i draw within the CGContextRef. Ofcourse i am catching touches to draw. While the drawRect method slowly draws lot's of existing objects the touches are not caught. If i call drawing in drawRect in separate thread or with function "dispatch_async" it doesn't draw because it has no appropriate context. I've seached a lot but found nothing. dispatch_async(dispatch_get_main_queue(), ^{ [_mainArea setNeedsDisplay]; }); these things do not help either. What can i

Manually color fading from one UIColor to another

房东的猫 提交于 2019-12-05 03:45:15
I'm trying to fade one UIColor to another in a drawRect . I've created this function to calculate a color at a certain percentage: - (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor percent:(float)percent { float dec = percent / 100.f; CGFloat fRed, fBlue, fGreen, fAlpha; CGFloat tRed, tBlue, tGreen, tAlpha; CGFloat red, green, blue, alpha; if(CGColorGetNumberOfComponents(fromColor.CGColor) == 2) { [fromColor getWhite:&fRed alpha:&fAlpha]; fGreen = fRed; fBlue = fRed; } else { [fromColor getRed:&fRed green:&fGreen blue:&fBlue alpha:&fAlpha]; } if