I created qpushbuttons with qtdesigner and as a default I want to make them disabled without clicking them in other words before the dialog screen comes they should already have been disabled.I ask that because I write a cinema seat reservation and when somebody buy the seat I make it disabled and the color red but after closing and re-running the program they disappear and they turn to default. I want to do is; when I re-run the program they should be seen disabled and color red. How can I do that. Thank you.
You can do that from QtDesigner, the advantage being you don't need to code anything.
Select your QPushButton, and make sure the enabled property is not checked.
Before you call yourDialog->show(), execute yourDialog->yourPushButton->setDisabled().
Related
qApp->setOverrideCursor() method works successfully, if I want to hide mouse cursor, except one condition. If I add a dialog that is modal, and while it is shown, if the cursor is out of dialog's borders, it is shown again. Have you got any idea about the problem?
It does not matter how the solution for hiding mouse cursor is; whether by Qt or at the operating system level. My operating system is Windows 7.
You cannot hide the mouse cursor when it leaves your window (or dialog-window), because it is then handled by the window-manager of your OS. A workaround would be to constrain the mouse to your window/dialog, so it cannot leave. You will either need to look through the MSDN to find the specific windows functions to do it, or do it like in kshegunov's code example on the Qt-forums: https://forum.qt.io/topic/61832/restrict-mouse-cursor-movement/12
Please see this gist to see what I am trying to achieve: https://gist.github.com/d9e22915234e6ea34d20
The code is heavily cut down on the problem I face. As you can see when running the code there is a "miss" detected on the label or the text area (if you miss it by 5em or whatever). Unfortunately this does not work for the Dialog's own buttons OK and Cancel (Please run the code and you will see immediately what i am talking about). If you click near an FX-Node it should detect wheter you missed it or not.
Does anybody know if it is possible to detect clicks in the Dialogs button area?
And if it is possible, how to link them to the node like the label and the area?
Thank you in advance.
From what you're seeing, I would guess that the Dialog consumes click events in the button bar, so they don't make it to the Window (which is where you added the EventHandler). If you really want to do this, you can change addEventHandler to addEventFilter. This works for me.
Read this tutorial if you want to find out why this works:
http://docs.oracle.com/javase/8/javafx/events-tutorial/processing.htm#CEGJAAFD
Half of my answer was found here: How to prevent QSpinBox from automatically highlighting contents
However, the program still allows for a mouse or touch-drag to highlight the values of the spinboxes. I need absolutely no highlighting as my application is for an embedded device interface.
How do completely disable highlighting of any kind while still maintaining the spinbox up/down button functionality.
What we ended up doing was to connect a couple signals to the textEditDeselect slot.
foreach(QSpinBox* sb, ui.main->findChildren<QSpinBox*>())
{
sb->findChildren<QLineEdit*> ().at(0)->setReadOnly(true);
connect(sb,SIGNAL(valueChanged(int)),this,SLOT(textEditDeselect()), Qt::QueuedConnection);
connect(sb->findChild<QLineEdit*> (), SIGNAL(cursorPositionChanged(int,int)),this, SLOT(textEditDeselect()),Qt::QueuedConnection);
}
The easiest solution is to change the palette in Qt Designer.
Select qspinbox, click "Change Palette" and for HighlightedText choose black color. This will disable blue background, at least on windows.
I need on my form ordinary widgets (e.g. buttons) do not react on mouse clicks but NOT to be disabled (it change look to grayed one -- not good).
I wonder is there some neat small hack for this?
You could stick in an event filter and filter out the mouse events before passing the remaining events on for processing, but I'm not sure that not giving the user a visual clue that certain elements are effectively disabled is such a good idea.
You could try using style sheets to control how the disabled mode of the buttons in your form get styled. Unfortunately I'm not sure exactly how to do that but you could have a look at the style sheet docs to get you started.
Say I have some state which the user can toggle, for example [ON] | [OFF] .
Typically, I use ONE switch (BUTTON) and when the thing is ON, the user sees:
LIGHT IS [ON]
When it is OFF they see
LIGHT IS [OFF]
My question is: is it obvious (sensible) that one should click [ON] to turn the light [OFF]?
How do you do it? Any thoughts or ideas appreciated.
I would use a label and an button to show the action.
Light is On - Switch Off?
Clicking that would change both the label and the button to:
Light is Off - Switch On?
This solution clearly states the status and the action available.
I would definitely include the notion of a checkbox-like control if clarity is your concern. This is a widely accepted interface component, that most people understand.
In any case you can make the entire line clickable, so that it toggles when I click the text as well (just like an HTML Label element).
Showing a button with just the text 'ON' might confuse users whether it toggles the light on, or if the current state is 'on'.
An image speaks a thousand words...
Depending on the type of application, displaying a light switch image that you can click
to set the state of the field might be more intuitive?
You could then have a lightbulb-on and lightbulb-off image to show state.
Not everyone knows what a checkbox is ;)
You could use radio boxes, which are fairly standard controls and should not be confusing to most people.
<input type="radio">Light on<br>
<input type="radio">Light off
Another option is to try and implement some sort of switch button, something like this one that is used on the iPhone:
Switch button in iPhone - off http://www.poolworksbvi.com/POOL_CONTROL/Pool1_files/iphone_switch.png
Switch button on iPhone - on http://www.poolworksbvi.com/POOL_CONTROL/Pool1_files/iphone_switch+on%20copy.png