I am new to the whole QT things, so please bear with me :-)
I am working on a program that has a QMainWindow with a couple of menu options. I then use QActions to call functions to do something with the menu options.
I have put together a QDialog, which shows when called directly, but not when called through the QAction dialog.
Code:
Constructor Code
View::View(QWidget *parent):QMainWindow(parent)
{
QWidget *topFiller = new QWidget;
topFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(5);
layout->addWidget(topFiller);
setLayout(layout);
createActions();
createMenus();
change(); //Works but displayed as a separate window
QWidget::setWindowTitle( "Stock Editor");
setMinimumSize(300, 300);
resize(680, 520);
}
QAction Snippet
changeact = new QAction(tr("&Change"), this);
connect(saveact, SIGNAL(triggered()), this, SLOT(change()));
Change() Function
void View::change()
{
QDialog *dialogWin = new QDialog(this);
dialogWin->setWindowTitle("Add Item");
QFormLayout *formLayout = new QFormLayout();
QLineEdit *barcodeLineEdit = new QLineEdit;
QLabel *barcodeLabel = new QLabel("Barcode");
QLineEdit *descLineEdit = new QLineEdit;
QLabel *descLabel = new QLabel("Description");
QSpinBox *stockSpinBox = new QSpinBox;
QLabel *stockLabel = new QLabel("Stock");
QSpinBox *priceSpinBox = new QSpinBox;
QLabel *priceLabel = new QLabel("Price");
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
// connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
// connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
formLayout->addRow(barcodeLabel, barcodeLineEdit);
formLayout->addRow(descLabel, descLineEdit);
formLayout->addRow(stockLabel, stockSpinBox);
formLayout->addRow(priceLabel, priceSpinBox);
QVBoxLayout *mainLayout = new QVBoxLayout(dialogWin);
mainLayout->addLayout(formLayout);
mainLayout->addWidget(buttonBox);
dialogWin->setLayout(mainLayout);
dialogWin->activateWindow();
dialogWin->show();
}
How can I get the box to appear on top of the Main Window when called?
Thanks for the assistance
Related
UPDATE:
I've tried implementing this in an App.cs method called OpenCameraScanner (you would call this on click of a button on the page from which you want to scan):
App.cs
------------------------------------------------
public static ZXingScannerPage ScanPage;
public static ZXing.Result ScanResult;
public static async void OpenCameraScanner()
{
ScanPage = new ZXingScannerPage(customOverlay: customOverlay);
ScanPage.OnScanResult += (result) =>
{
ScanPage.IsScanning = false;
ScanResult = result;
Device.BeginInvokeOnMainThread(() =>
{
App.CurrentApp.CurrentPage.Navigation.PopModalAsync();
App.CurrentApp.CurrentPage.DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
var scanPage = new NavigationPage(ScanPage);
await App.CurrentApp.CurrentPage.Navigation.PushModalAsync(ScanPage);
}
However, when this method is called, the screen that opens is blank white, and you can't see the camera view behind it. Not sure why?
I'm using ZXing.Mobile in a Xamarin.Forms project (for iOS right now) for camera scanning functionality on an iPad.
Currently, I have it working great with the following 2 lines:
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
However, when the camera is open to scan, it takes up the entire iPad screen, which is really big.
Question: Is there a way to adjust the size of the camera overlay? (so that it's not full screen)
I see that the scanner.Scan() method takes an optional options parameter of type ZXing.Mobile.MobileBarcodeScanningOptions - I tried playing around with that, but the only possible relevant option there is a CameraResolutionSelector - but I'm having a really hard time finding any documentation on that.
There is a ZXing sample app that shows how to embed the ZXingScannerView and ZXingDefaultOverlay into a Xamarin.Form's Grid:
https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/CustomScanPage.cs
public CustomScanPage () : base ()
{
zxing = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingScannerView",
};
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread (async () => {
// Stop analysis until we navigate away so we don't keep reading barcodes
zxing.IsAnalyzing = false;
// Show an alert
await DisplayAlert ("Scanned Barcode", result.Text, "OK");
// Navigate away
await Navigation.PopAsync ();
});
overlay = new ZXingDefaultOverlay
{
TopText = "Hold your phone up to the barcode",
BottomText = "Scanning will happen automatically",
ShowFlashButton = zxing.HasTorch,
AutomationId = "zxingDefaultOverlay",
};
overlay.FlashButtonClicked += (sender, e) => {
zxing.IsTorchOn = !zxing.IsTorchOn;
};
var grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
};
grid.Children.Add(zxing);
grid.Children.Add(overlay);
// The root page of your application
Content = grid;
}
I've created an activity indicator and added it to StackLayout and when I make it running, in the emulator it shows in the top right corner Android 4.4 and in iOS no show and in Android 6 phone, it don't show.
var indicator = new ActivityIndicator()
{
Color = Color.Blue,
};
indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy", BindingMode.OneWay);
indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy", BindingMode.OneWay);
AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
mainLayout.Children.Add(indicator);
I want to show the activity indicator to the center of the screen because the operation takes time to complete.
The indicator that you are seeing in the status bar is the default behavior of the IsBusy property of the base page class. The reason your code isn't working is because you are attempting to bind visibility of your ActivityIndicator to that property - but you aren't specifying a binding source. If you look in your debugger's application output log then you will probably see messages along the lines of "Property 'IsBusy' not found on type 'Object'".
To fix it, you simply need to point the Binding Context of each binding to the form. Give this a try:
public partial class App : Application
{
public App ()
{
var mainLayout = new AbsoluteLayout ();
MainPage = new ContentPage {
Content = mainLayout
};
var containerPage = Application.Current.MainPage;
var indicator = new ActivityIndicator() {
Color = Color.Blue,
};
indicator.SetBinding(VisualElement.IsVisibleProperty, new Binding("IsBusy", BindingMode.OneWay, source: containerPage));
indicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding("IsBusy", BindingMode.OneWay, source: containerPage));
AbsoluteLayout.SetLayoutFlags(indicator, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(indicator, new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
mainLayout.Children.Add(indicator);
containerPage.IsBusy = true;
}
}
You add your activity indicator to stack layout, but you are setting Absolute layout LayoutFlags, they won't work.
to be able to achieve what you want, you need suck structure
AbsoluteLayout
StackLayout
ActivityIndicator
mainLayout should be AbsoluteLayout, all content should be contained in nested StackLayout.
I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.
I have a search form that opens in a com.smartgwt.client.widgets.Window.Window(). In it, I have a VLayout, in which I have a search form:
DynamicForm search = new DynamicForm();
// setMargin, setTitle, setNumCols
TextItem name = new TextItem();
name.setFormatOnFocusChange(true);
//setEditorValueFormatter, etc.
search.setFields(/*some fields*/, name, /*other fields*/);
name.focusInItem();
And the focus is not in the item (it's nowhere). Why is that so?
Thank you in advance!
EDIT:
Here is the code of the two Mediators:
public class MainMediator extends Mediator {
private Window popup = new Window();
protected void initView(){
// here I have a Form with fields and icon on one TextItem, on which I do:
searchField.addIconClickHandler(new IconClickHandler() {
popup = new Window();
popup.setIsModal(true);
popup.setShowModalMask(true);
});
}
public final void handleNotification(final INotification notification){
// if the right notification is sent, execute this code:
PopupMediator m = (PopupMediator) this.getFacade().retreiveMediator(PopupMediator.NAME);
VLayout popupLayout = (VLayout) m.getViewComponent();
popup.addItem(popupLayout);
popup.show();
}
}
public class PopupMediator extends Mediator {
protected void initView(){
viewComponent = new VLayout();
DynamicForm searchForm = new DynamicForm();
// searchForm props
TextItem name = new TextItem();
// name props and some other fields
searchForm.setFields(name /* and the others */);
VLayout searchFormContainer = new VLayout();
// searchFormContainer props
searchFormContainer.setMembers(seachForm);
name.focusInItem(); // not working on popup shown
HLayout searchContainer = new HLayout();
// searchContainer props
searchContainer.setMembers(grid1, searchFormContainer);
VLayout container = new VLayout();
// container props
container.setMembers (searchContainer, grid2);
((VLayout)viewComponent).setMembers(container, buttons);
}
You're getting this problem because formitem.focusInItem() works only after the formitem is drawn or say rendered in the browser. Adding the formitem in DynamicForm does not draw it.
I don't know where you're placing the DynamicForm, but to understand it completely, look at the following code:
Window window = new Window();
window.setSize("900px", "500px");
VLayout layout = new VLayout();
DynamicForm dynamicForm = new DynamicForm();
dynamicForm.setSize("800px", "400px");
TextItem item = new TextItem();
dynamicForm.setFields(item);
item.focusInItem(); // This won't work.
layout.addMember(dynamicForm);
window.addItem(layout);
item.focusInItem(); // This won't work.
window.show();
item.focusInItem(); // This will work.
So change your code accordingly.
Not sure how you receive handleNotification() callbacks, but you shouldn't use window.addItem() in it.
That will cause multiple items to be added/overwritten each time callback is called.
If handleNotification() callback is required, it should be only used for window.show(), plus any form field population/setting focus/etc.
If the content of Window is NOT going to change from one callback to another, initialize window layout during window creation.
If content of Window is GOING to change from one callback to another, you will need to remove previously added items.
Here's a simple working implementation that popup the window on a button click and set focus on a given field.
TextItem name1 = new TextItem("name1", "Name 1");
final TextItem name2 = new TextItem("name2", "Name 2"); // setting focus to name2
TextItem name3 = new TextItem("name3", "Name 3");
final DynamicForm searchForm = new DynamicForm();
// searchForm.setAutoFocus(true); // sets focus to first focusable field
searchForm.setFields(name1, name2, name3);
VLayout searchFormContainer = new VLayout();
searchFormContainer.setMembers(searchForm);
final Window window = new Window();
window.setIsModal(true);
window.setShowModalMask(true);
window.setAutoCenter(true);
window.setSize("400px", "300px");
window.addItem(searchFormContainer);
Button button = new Button("Search");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
window.show();
name2.focusInItem();
// searchForm.focusInItem(name2); // this also works
}
});
Its possible to use DynamicForm.setAutoFocus to automatically focus on first focusable field in the form.
Why don't you try to focus on the form itself:
search.focus();
I was trying to create two different kinds of buttons: buttons with background and buttons without background.
And unfortunately I can't figure out how I can set some buttons to use the first style and some buttons to use the second.
Here's a code sample (although i doubt it'll help)
Is there some way to change the Style of the button in the .cs file, or any workaround?
//init hyperlink
Button hyperlink = new Button();
Label hyperlink_label = new Label();
hyperlink_label.Text = hyperlink_text;
hyperlink_label.ModifyFg(StateType.Normal, new Gdk.Color(0,0,0));
hyperlink_label.ModifyFg(StateType.Prelight, new Gdk.Color(255,255,255));
hyperlink_label.ModifyFg(StateType.Selected, new Gdk.Color(255,255,255));
Pango.FontDescription hyperlinkFontDesc = new Pango.FontDescription();
hyperlinkFontDesc.Family = "Adobe Garamond Pro";
hyperlinkFontDesc.AbsoluteSize = hyperlink_fontSize * Pango.Scale.PangoScale;
hyperlink_label.ModifyFont(hyperlinkFontDesc);
hyperlink.Add(hyperlink_label);
mainWindowFixed.Put(hyperlink, hyperlink_pos[0], hyperlink_pos[1]);
//init startbutton
Button startButton = new Button();
Label startLabel = new Label();
startLabel.Text = startButton_text;
startButton.Settings.ThemeName = "Ludwig_AutoUpdater";
startLabel.ModifyFg(StateType.Normal, new Gdk.Color(255,255,255));
startLabel.ModifyFg(StateType.Prelight, new Gdk.Color(255,255,255));
startLabel.ModifyFg(StateType.Selected, new Gdk.Color(255,255,255));
Pango.FontDescription startLabelFontDesc = new Pango.FontDescription();
startLabelFontDesc.Family = "Klavika bd";
startLabelFontDesc.AbsoluteSize = startButton_fontSize * Pango.Scale.PangoScale;
startButton.Add(startLabel);
startButton.Child.ModifyFont(startLabelFontDesc);
startButton.SetSizeRequest(startButton_size[0], startButton_size[1]);
mainWindowFixed.Put(startButton, startButton_pos[0],startButton_pos[1]);
Don't change the style of Gtk.Button. Create a custom widget derived from Gtk.Button and change that widget's style. For example:
public class BGButton : Gtk.Button {}
and
public class NoBGButton : Gtk.Button {}
and now change the style of BGButton and NoBGButton.
Then if you want a Button with a Background use BGButton , else use NoBGButton.