iOS Qt - Load QWidget inside UIView? - ios

Hopefully my question will make sense. Just started with Qt so bear with me.
I have an app in Objective-C (for iOS) and I'm trying to add a piece of code in Qt into it.
Most of the UI is in Objective-C (meaning I got UIViews, UIViewControllers, ...) and only a part of it should be handle in Qt.
To create a UI element in Qt, I guess I need to create something that inherits from QWidget.
But how would I set the parent of this QWidget to one of my UIView element?
I understand it would be easier to do everything in Qt, but that is just to much work so that is why I am hoping I can keep part of my UI in Objective-C and the other part in Qt.
Thanks for your help
--
Edit
Well I was following the example from here. Even if it is for Mac OS.
QWidget * qWidget = new QWidget();
qWidget->move(0, 0);
qWidget->setPalette(QPalette(Qt::red));
qWidget->setAutoFillBackground(true);
QVBoxLayout *layout = new QVBoxLayout();
QPushButton *pushButton = new QPushButton("An Embedded Qt Button!", qWidget);
pushButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
layout->addWidget(pushButton);
qWidget->setLayout(layout);
// Adjust Cocoa layouts
UIView *uiWidgetView = (__bridge UIView *)((void*)qWidget->winId()); // Fancy cast for ARC
// Add the widget
[self.view addSubview:uiWidgetView];
qWidget->show();
pushButton->show();
But it does not seem to work for iOS...
I have two messages:
- This plugin does not support propagateSizeHints()
Do not know how to fix that one
- QIOSBackingStore needs to have the same size as its window
This one is referenced here. Does not seem to be fixed yet.
Note: Adding a simple uiview (like a uilabel) to my current view works fine. Just this one that does not seem to render for some reason... :s

Related

How can i make customizable views on IOS ? (i used style.id as a parameter on android view class constructor)

First I want to talk about what I exactly did on Android, and I am now trying to do the same on IOS :
I developed a library on Android which contains an activity, in that activity we have several type of views (labels, buttons ... etc).
These views are used as an entry point/inputs for my library that provides some services to other apps.
To be able to match the general style of the user app, I created my own View Classes, the user(of my library) needs to provide a style id to the activity before launching it, so it can be used when constructing the View.
Doing so, we are able to maintain the style of the app without the need to re-implement the views for every app that uses my library or making the user(final user on physical device) feels as if he just moved out to another app.
I am really a newbie on iOS and I recently started to learn it so i am not sure how to do it, can you please provide me some guidelines please?
On iOS there are so many ways to create views (xibs, Storyboards , SwiftUI, and programatically). I am not really sure where to start.
He's a sample of my code on Android :
class MyView(val context: Context, val themeId: Int) : View(context) {
init {
val wrappedContext = ContextThemeWrapper(context, themeId)
val mInflater = wrappedContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
mInflater.inflate(R.layout.my_view_layout, this, true)
}
}
This is a very broad question, but the short answer is "sure, it can be done."
I suppose a quick example might be:
I have a custom UIView with a UILabel centered in it, with 20-pts padding on all 4 sides.
I have 4 "themes" defined, defining the view's background color, the label's text color and the label's font style.
I write a custom init func to accept an Int "id" of 1 through 4
The library user could then instantiate it along the lines of let myView = MyView(with themeId: 2)
As this is a very broad question (topic), once you start developing your custom view you could come back if you run into specific coding questions.

How to set preferredRenderingAPI for ARSCNView in Xcode IB

In my ARKit application ARSCNView is initialized and attached to ViewController internally based on storyboard file structure. So in function viewDidLoad I have already initialized view.
But the problem is it uses default rendering API metal. But I would like to change it to OpenGL ES2. In Apple documentation I read that preferredRenderingAPI can be somehow changed in IB inspector. But I don't understand how. There are no any examples of how to do this?
Or maybe I still change it from the code, even though the view is initialized from IB?
Just open your Main.storyboard (or whatever you have) in Xcode and navigate to the node Scene View of type SCNView in there. The Attributes inspector should allow you to change the renderer (Rendering API).
I've just tested it but it looked like my project didn't work the same as with metal.

Rendering UIView in Swift with #IBDesignable, crash

I have a graph built in Paintcode that I am showing in a UIView. It works fine in the App but will not render in storyboard. I have read a host of different posts about overriding init frame, and init coder. However, I can't find a specific example that helps me with my problem, by showing the practical use of these overrides.
The graph takes 14 variables to produce a bar chart. Here is the class code
import UIKit
#IBDesignable
class graphRisk: UIView {
override func drawRect(rect: CGRect) {
StyleKitGraph.drawRiskGraph(ehsScale: ehsScale, ciScale: ciScale, stratScale: stratScale, qaScale: qaScale, delScale: delScale, leadScale: leadScale, peopScale: peopScale, hrmScale: hrmScale, pmScale: pmScale, costScale: costScale, finScale: finScale, assScale: assScale, itsScale: itsScale, engScale: engScale)
}
}
It looks good in the App, and it is no big deal if it doesn't render as the variables are coded, and the design is fine, however, I removed the #IBDesignable tag and it still errors the same.
Finally, how do I get the UIView to update when I enter the view controller it resided in?
So the questions are;
1 How do I get render to work for this code example?
2 Is there a way to not render the view, and stop the error that way?
3 Do I need to worry about the error as the App runs fine?
4 How do I get the UIView to refresh. What is the syntax for .setNeedsDisplay() etc? I tried lots of things and none updated or reloaded or refreshed.
As always I truly welcome all help, and thank you.
Not sure what version of Xcode you are using. I am using Xcode 6.4.
I, like you, have researched for days on many websites and tried many solutions. None of them worked. At last, I removed the #IBDesignable to my custom UI class. Not only did the error went away, the instance of the custom UI class previewed fine in Main.storyboard.
Perhaps, in the new development of Xcode, #IBDesignable is no longer necessary.

Adding array of UIImage in a UIViewController with some alignment

I just started my first project in iOS, recently I have encountered a problem in the UI when i receive it from the designer.
The expected output is shown as below and i can do most of it without any problem.
Now the problem came when I am about to implement this :
As the number of colour varies depending on item, I cannot add it like what I did for the share and love button I have no idea how can i implement something like this, I have look through the Object Library in the storyboard and cannot find any that can produce the output as expected .Any helps and guides are much apprecited!

Xamarin.forms and immediate mode graphics

Does anybody know how to draw immediate mode graphics into a xamarin.forms view?
I need to draw some app specific graphics into a form. I've been googling and looking at examples for a lot of the day. I know about Renderers. I can almost do it, but ViewRenderer can't be easily subclassed (unless I'm missing something), and I can't find an existing view subclass that is suitable.
Sometimes my own stupidity and thickness surprises even me.
The answer is to create a concrete, OS-dependent View for each platform. Then create a ViewRenderer implementation for each platform.
The platform-specific ViewRenderer<...> then instantiates the platform-specific view. And we're off to the races.
There are minor details, such as how to communicate or acquire view size and parentage, but at least those are known problems.
So, you have the following components:
A MyXamarinFormsView, which sub-classes Xamarin.Forms.View. MyView doesn't actually have to contain any significant logic. Think of it as a placeholder.
For each platform:
A MyXamarinFormsViewRenderer : ViewRenderer<MyXamarinFormsView, MyPlatformSpecificView>
Add the following attribute instance to each ViewRenderer, after any using statements and before the namespace declaration (if there is one):
[assembly:ExportRenderer( typeof( MyXamarinFormsView ), typeof( MyXamarinFormsViewRenderer ) ) ]
A MyPlatformSpecificView : platform-specific View (e.g. UIView for iOS)
Put the graphics-specific code in each platform-specific view subclass.
I'm not certain if this is the official/correct way of doing it, but it does appear to work for me.

Resources