GTK# button drawn incorrectly? - button

My GTK# (v2.12.44) app has a single Window with a single button on it. The button appears to be centered on the Window, because that's where the text appears, but the border/background for the button is shifted up and to the left for no reason I can see. Has anyone seen this before? I saw similar behavior from an Image widget. Note this only happens in Windows, not on (for example) Raspberry Pi/Jesse.
Here's the code:
Application.Init();
var window = new Window("test") {new Button("testing 1, 2, 3")};
window.Maximize();
window.ShowAll();
Application.Run();

Your code works well. Try to add a container before adding a button and set some parametrs you want to. Fill and Expand when adding Button.

Related

Make an Independent Popup in Qt Quick

I have an app which is small in terms of width and height, I want a popup to show when a button is clicked. Problem is the popup is larger than the app window and when i open it, it scales down and looks weird
APP
APP WITH POPUP
POPUP CONTENT IN DESIGNER
How can i make the popup independent from the app window, like this:
Or is there a better approach rather than using popup, it would be nice if i were able to move the popup/window around. It still needs to be somehow connected to the main app because it get's data from there
A Popup in QML appears as a layer on top of the parent window, so it cannot be bigger than the parent window. If you want a separate, top level window, you should use a Window or a Dialog instead.
I've gotten it sorted out. I encapsulated the component i wanted to show inside a window and created it using Qt.createComponent()
var playListComponent = Qt.createComponent("CustomPlaylist.qml")
var window = playListComponent.createObject(rootWindow)
window.show()
The root element of CustomPlaylist.qml is a Window

QDialogBox flickers

I create a custom QDialogBox class and try to display it in the centre of my window using the 'move' command. However, I am facing an issue.
The dialog box appears at a random position on the screen and then moves to the position set by me after 1 second. This happens at random instances. I open the dialog box 10 times and I do not see this flickering. However, this happens the 11th time. There is no specific pattern. Is this a performance issue? This happens more frequently on slower machines.
If I run the dialog box as loginDialog->show(); the flickering is not there. However, it happens when I use: loginDialog->exec(). How can I resolve this issue?
CustomDialog *loginDialog = new CustomDialog( this );//a QDialogBox class
float width=350,height=180;
dialogBoxPosition(&width, &height);
_mFinalPoint.setX(width);
_mFinalPoint.setY(height);
loginDialog->move(_mFinalPoint);//moving it to a window center
loginDialog->loginWindow();//calling a member function
loginDialog->exec();

Center buttons in dialog created with "gtk_dialog_new_with_buttons"

I am writing a Gtk application and I am having troubles centering some buttons.
I created a popup window in this way:
dialog = gtk_dialog_new_with_buttons ("Add element",
GTK_WINDOW(gElems->window),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
"OK",
GTK_RESPONSE_ACCEPT,
"Cancel",
GTK_RESPONSE_REJECT,
NULL);
Everything is ok, except for the OK and Cancel buttons, which are aligned to the right end of the popup window, while I would like them to be centered (as you can see from the picture).
Is there a way to do so without using additional containers to store the buttons?
You can align the buttons in the middle
buttons_container = gtk_dialog_get_action_area (dialog)
g_object_set_property (G_OBJECT (buttons_container), "halign", GTK_ALIGN_CENTER)
and voila.....
If you want to change the container, you also can, but that's not what you want, really
Regarding luciomrx answer: It is needed to pass a gvalue, otherwise you will get a compile warning and a runtime crash:
GValue val = G_VALUE_INIT;
g_value_init (&val, G_TYPE_ENUM);
g_value_set_enum (&val, GTK_ALIGN_CENTER);
buttons_container = gtk_dialog_get_action_area (dialog);
g_object_set_property (G_OBJECT (gtk_dialog_get_action_area (dialog)), "halign", &val);
Even Simpler, you can just use gtk_widget_set_halign, which accepts an enum:
gtk_widget_set_halign (gtk_dialog_get_action_area (dialog), GTK_ALIGN_CENTER);
Edit: I just realized that gtk_dialog_get_action_area anyhow is deprecated in gtk3 .. so a different sulution should be found.

MonoTouch Rotated Button when Added in Code

I have a basic iPad app created using MonoTouch. I have a single view controller.
In code I am adding a button like this:
_button = UIButton.FromType(UIButtonType.RoundedRect);
_button.Frame = new Rectangle((int)location.X - 50, (int)location.Y - 50, 100, 100);
_button.SetTitle("A", UIControlState.Normal);
_viewController.View.AddSubview(_button);
This work great when the iPad is in Portrait mode. If I rotate the screen before adding the button and then try to add the button then it is rotated.
For example if the orientation is currently LandscapeLeft (hardware button on the left side) then when I add the above button the letter A on the button is laying on its right side as if the button is rotated 90 degrees to the right.
How do I add a button in code so that it will always be oriented correctly?
Turns out it was because I was adding the button to the View.Window (for other reasons). I had changed it to adding the button to the View instead and now it works.
False alarm. Learn something every day....
Maybe this can help you:
UIButton button = new UIButton();
...
button.Transform = CGAffineTransform.MakeRotation();
this is a function to rotate the Button;)

How do I resize the dropdown of a combobox along with the combo box?

Background:
I am doing some UI work where I allow the user to programatically add and resize controls on a canvas.
Problem:
When resizing a combo box through AS the dropdown stays at the same width as the first time it drops down. So user places combo box on the page, clicks the down arrow, sees the options, selects an option or clicks down arrow again to close, resizes the width of the drop down, clicks the down arrow. Now drop down is the same width as original.
Have tried simple things like setting the width of the dropdown specifically and invalidating display list but it still doesn't work.
Example:
Code Example pending
While trimming my code down to an example I solved my problem. A combobox has a dropdownWidth property. I was trying to set this myComboBox.dropdownWidth = newWidth, which doesn't work (not entirely sure why, didn't dig into the SDK). However if I change my code to myComboBox.dropdown.width = newWidth it actually goes to the dropdown element and re-sizes it directly which does work.
comboBox.dropdown.width did not work for me. I had to use
comboBox.dropdown.percentWidth = 100;
It seems to work without having to call invalidateSize()
In the ComboBox, overriding the set dataProvider and performing the following seemed to work, because the dataProvider field is bound to the collectionChange event.
ComboBox.calculatePreferredSizeFromData(count:int):Object
override public function set dataProvider(value:Object):void {
super.dataProvider = value;
var size:Object = calculatePreferredSizeFromData(dataProvider.length);
this.dropdownWidth = size.width;
this.dropdown.width = this.dropdownWidth;
this.invalidateSize();
}

Resources