I have a Qt Designer form (widget), that includes N radio buttons. And i want to see different options (QGroupBox, etc) depending on selected button in the same widget. What is the right way to solve this problem?
Of course, i can place all boxes in widget and change their visibility depending on selected radio button, but that is not perfect i'm sure.
It seems like QStackedWidget is what you're looking for.
Put your radio buttons into a QButtonGroup, then connect QButtonGroup::buttonClicked(int) to QStackedWidget::setCurrentIndex(int).
Related
I need to change the style of 4 of my p:selectBooleanCheckBox to style it as radio button.
In more detail: if you would style check boxes as radio boxes, you will confuse the user, as multiple options can be selected, which is not the case with radio buttons. With radio buttons you can only select one option. So, I suggest to simply switch to radio buttons instead of trying to hack your way out of this.
If you really want to style your checkboxes, have a look at How do I override default PrimeFaces CSS with custom styles? But again, think hard before doing so.
The source of the free themes is open. See for example https://github.com/primefaces/primefaces/blob/master/src/main/resources/META-INF/resources/primefaces-saga/theme.css and search for radiobutton.
In Microsoft Word, if you want to use Bullets you have a combo box (If we can call it a combo box) to select the shape of the bullet (by clicking the little triangle) or you can just apply the default one by clicking the combo box's button.
Actually the combo box in Word has two parts. For an example let's consider a situation where I want to have a combo box in Qt that has these items as menu items:
"Restart", "Shutdown" and "Log off". User needs to choose one of them but he also can apply previously selected item by clicking its button exactly like Windows shutdown menu in start. You can click Shut down or select another option.
How can we achieve this in Qt?
If you are pursuing after a menu that looks like in the second picture, you can use QToolButton to achieve your goal. Use a QToolButton with popupMode set to MenuButtonPopup. It will render a control something similar to following.
Then you can style the look & feel further more using Qt Style Sheets. Read this example on how to style a QToolButton.
Create a QMenu dynamically, so you can attach it to the QToolButton at run-time in such a way that all items will be included in the menu except for the default item. Default action has to be assigned to the QToolButton itself.
You can use void QToolButton::setMenu (QMenu * menu) to assign a QMenu to your QToolButton at run-time.
If you are trying to design a control that is in your 1st screenshot, you will have to create a custom Qt control I guess. There is no default control available, which can yield that look & feel out of the box.
I want to create a squared radio button, with the text inside the button. Is that possible? I think the button shape could be changed trough css, but what about the text?
Any hint?
Rather than trying to deform a QRadioButton into something which visually resembles a QPushButton, I would simply use a QPushButton with some custom logic.
You won't have to worry about the visual aspect then, while the logic itself is not all that hard to write.
As stated by #besworland, QPushButton inherits from QAbstractButton, which already has the option to be checkable or not. You can set this via setCheckable(bool).
To mimic the "exclusive" behaviour of a set of QRadioButtons, you can add your buttons to a QButtonGroup and make it an exclusive one. As stated in the documentation "An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked." You can use a QButtonGroup's setExclusive(bool) method for that.
In any case, I would consider those easier options than transforming a QRadioButton to fit your needs.
I want to create radio buttons or other type of controls that will act like this:
[_value1_] [value2] [value3]
Value1 is selected, so it looks like pressed button or selected link (bold, no underline) and other elements are active buttons/links. When user select another value - state is changed. I can handle this event manually, question is - what plugin or existing css/js combination should I use to achieve this?
I am pretty sure that this type of controls have a name, but can't think out what is this. I have tried to search for custom style radio buttons, as functionality is the same, but failed. Also I have tried some other names such as switch buttons, but it's not what I want. It's also very similar to tabs, but tabs usually styled as something that require underline div attached. So I am looking for "radio button meet tabs" css/js solution.
Can you help me to name this control, if you know it's name, or find plugin/existing code that can help me to achieve my goal?
The question is not how to create this type of functionality myself, I can do it, but it's rather strange that there are no existing solutions and I want to help people in same situation, also may be existing solutions design can be better than I can invent myself, because I am not a designer.
Answer
This type of controls can be found as "Simplified CSS Tabs" or "CSS Mini Tabs", but they require some additional code to work as expected.
Also, this type of functionality can be found in Google as jQuery UI radio buttons transformed into a button set and Yahoo UI Button Control: Radio Buttons
http://jqueryui.com/demos/button/#radio
works done for ya bud :)
On Linux would like to have a set of menu items which are mutually exclusive and have the currently selected one be designated by a radio button instead of a checkbox.
Is there a way to do this in Qt v4.4.3 easily?
I believe you would want to use QtActionGroup to group those menu items which should be mutually exclusive. It also makes them look like a radio button when rendered. Smth like this:
QActionGroup* group = new QActionGroup( this );
ui->actionTest1->setCheckable(true);
ui->actionTest2->setCheckable(true);
ui->actionTest3->setCheckable(true);
ui->actionTest1->setActionGroup(group);
ui->actionTest2->setActionGroup(group);
ui->actionTest3->setActionGroup(group);
3 menu items above should be groped together; more details here : QActionGroup Class Reference