Qt checkbox/toolbutton with custom/distinct check/unchecked icons - c++

I need to have a checkbox like control where the checked and unchecked states use a custom graphic. I've looked at all the docs for QToolButton and QCheckBox, along with QIcon but couldn't find any combination that does what I want.
I just want to use one icon (pixmap actually) in the unchecked state, and a different one in the checked state.
This feels like it should be easy, but the solution (short of a custom control) is eluding me.
I've tried using a style sheet as well, and QToolButton:checked with a background-image kind of works but I can't get the layout correct -- it's not positioned/sized as with an icon.

Use ::indicator sub-item. the code below works excellent for me...
QCheckBox::indicator {
width: 18px;
height: 18px;
}
QCheckBox::indicator:checked
{
image: url(.../Checkbox_checked_normal.png);
}
QCheckBox::indicator:unchecked
{
image: url(.../Checkbox_unchecked_normal.png);
}
QCheckBox::indicator:checked:hover
{
image: url(.../Checkbox_checked_hovered.png);
}
QCheckBox::indicator:unchecked:hover
{
image: url(.../Checkbox_unchecked_hovered.png);
}
QCheckBox::indicator:checked:pressed
{
image: url(.../Checkbox_checked_pressed.png);
}
QCheckBox::indicator:unchecked:pressed
{
image: url(.../Checkbox_unchecked_pressed.png);
}
QCheckBox::indicator:checked:disabled
{
image: url(.../Checkbox_checked_disabled.png);
}
QCheckBox::indicator:unchecked:disabled
{
image: url(.../Checkbox_unchecked_disabled.png);
}

This must be entered as a StyleSheet. Do this via the Design editor by right click on the check box and selecting "Change stylesheet...".

You may also include and use your icons as resources:
QCheckBox::indicator:checked {image: url(:/circle-green.png);}
QCheckBox::indicator:unchecked {image: url(:/circle-red.png);}

Related

Semantic React Dropdown with search prop prevents styling

I'm changing the color of a dropdown's caret with
.myclass .ui.dropdown {
color:transparent!important;
}
This hides the caret, as expected, however not when I send the prop 'search' to the Dropdown component.
Has anyone faced this?
I've tried these alternatives
.myclass .ui.dropdown.search
.myclass .ui.search.dropdown
.myclass .ui.search
I also need to change it this way, rather than with icon=null, because I want to show the caret on hover with
.myclass .ui.dropdown:hover {
color: white!important;
}
Thanks in advance.
Answering my own question, shouldn't have given up so quickly. Leaving the post up for others:
SOLUTION:
.myclass .ui.dropdown i {
color:transparent!important;
}
.myclass .ui.dropdown:hover i {
color:white!important;
}
Although this doesn't explain why the search prop changes things, it works.

displaying image in a toolbar in swift 3

i am trying to create a toolbar with buttons. and the button i want to have is an image rather title. The current non working code is:
let imageName = "yourImage.png"
self.myUIBarButtonBack = UIBarButtonItem(image: UIImage(named: imageName), style:.plain, target: self, action: #selector(onClickBarButton))
I have 2 questions:
1. where should i place the yourImage.png in my application
2. is this code sufficient to render image or i need to do things like putting it into imageView component and make it visible etc. ?
The best approach is to add images in xcassets. This is the best way you can organize images. The concept of App slicing applies here.
You don't need to put the image in image view in the case of bar button item.
Try changing the rendring option as Original Image instead of Default.
One way is create custom button and assign to toolbar like navigationbar
self.navigationItem.hidesBackButton = true
let button = UIButton.init(type: .custom)
button.setImage(UIImage.init(named: "back_icon"), for: UIControlState.normal)
button.addTarget(self, action:#selector(onClickBackBarItem), for: UIControlEvents.touchUpInside)
button.frame = CGRect.init(x: 0, y: 0, width: 25, height: 25)
let barButton = UIBarButtonItem.init(customView: button)
self.navigationItem.leftBarButtonItem = barButton

How to use custom background image or color using Promotion

I am trying to build an iOS app using Promotion. It works fine as long
as I use the build in default design. But I want to be able to style for example
the navbar as I want (different colors and different background images).
How can I do this using Promotion?
Thanks!
You can use Teacup to easily customize your views. https://github.com/rubymotion/teacup
Add teacup to your gemfile, create a file appearence.rb in app/styles/appearence.rb and paste the following code:
Teacup::Appearance.new do
style UINavigationBar, {
tintColor: UIColor.blackColor
}
style UIBarButtonItem, {
tintColor: UIColor.blackColor
}
style UITableViewCell, {
layer: { # style the layer!
shadowRadius: 3
},
backgroundView: { # style the background!
backgroundColor: UIColor.blackColor
},
imageView: { # style the imageView!
contentMode: UIViewContentModeScaleAspectFill
}
}
style UISearchBar, {
tintColor: UIColor.colorWithRed(0.733, green:0.733, blue:0.733, alpha:1)
}
end
Add this line to your app delegate before loading your views
Teacup::Appearance.apply
Hope it helps.

Settings menu UI implementation

I'm trying to implement a BB10 settings menu, looking like the one in the Calendar app for example. The question here is, which components should I use? Using a ListView with an XML model looks great, but is incompatible with translation. Using a C++ model looks overkill for a simple menu with a couple of entries…
There's probably an established pattern somewhere, but I can't find it.
Screenshot of the Calendar app settings view
What you want is the expendable content property of the title bar:
I would create a QML object that you can re-use for each entry with properties for title and image.
So for example, something perhaps like this:
SettingEntry.qml
Container {
property alias title:title.Text
signal click()
TextView {
id: title
text: "[title goes here]"
}
gestureHandlers: [
TapHandler {
onTapped: {
click();
}
}
]
}
Then in your settings page you would use it like a normal object:
Page {
Container {
SettingEntry {
title: "General"
onClick: {
//open general page
}
}
SettingEntry {
title: "Invitation Settings"
}
}
}
The above is obviously very simplified, you would want to include an icon image, add translation code and add visual adjustments like filling the width and padding.
It should however give you a good idea of where to start.
I also included a gesturehandler and signal to show you how to handle events such as a click.

QML text scroll

I am using C++ and QML to create a nice interface.
I would like to have a "console view", where plenty to text is printed through time.
However, when the text of a text item or webview content grows, the view does not "scroll down".
How can I make the text on the bottom of the text/webview item always stay visible ?
I have tried playing with flickable and the_webview.evaluateJavaScript + window.scrollTo , but I could not get them to do what I want.
This seems a fairly simple piece of UI, but I am having serious troubles to do it with QML.
Thanks for you answer.
Yeah I'd use a Flickable containing a Text object. Whenever you add text to the Text, check its paintedHeight, and adjust the Flickable's contentY if it's got any bigger.
Maybe you should consider using a ListView and have the messages as items in the view. Then you could use ListView::positionViewAtEnd.
funkybro answers inspired my final solution:
function scroll_to_bottom() {
flickabe_item.contentY =
Math.max(0, webview_item.height - flickabe_item.height);
return;
}
Thanks !
My solution to this was to vertically flip both the content and Flickable. This way the text ends the right way up and is naturally anchored to the bottom of the flickable area.
It might be more efficient too since the transform is handled by OpenGL behind the scenes.
Flickable {
id: flick
anchors.fill: parent
contentHeight: text.height
Text {
id: text
width: parent.width
transform: Scale { yScale: -1; origin.y: text.height/2 }
}
transform: Scale { yScale: -1; origin.y: flick.height/2 }
}