Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Как создать группу кнопок (buttonGroup) в Дизайнере?
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt инструментарий
Andrewshkovskii
QButtonGroup через дизайне, это просто QGroupBox , и туда кнопочек напихать?:)
SABROG
Цитата(Andrewshkovskii @ 9.12.2009, 15:17) *
и туда кнопочек напихать?


Нет, тебе нужно выделить все кнопки, которые ты хочешь поместить в группу. Затем кликнуть правой кнопкой мышки и выбрать "Назначить новую группу кнопок"->"Новая группа кнопок". В коде уже использовать указатель на buttonGroup, создать слот в главном окне типа on_buttonGroup_buttonClicked(QAbstractButton * button).

   //обнулим матрицу
    for (int i=0;i<30;++i)
         for(int j=0;j<30;++j)
             matrix[i][j]=0;


Этот способ обнуления конечно работает, но так имхо будет правильней:

memset(matrix, 0, sizeof(matrix));
AD
Цитата(SABROG @ 9.12.2009, 15:34) *
Нет, тебе нужно выделить все кнопки, которые ты хочешь поместить в группу. Затем кликнуть правой кнопкой мышки и выбрать "Назначить новую группу кнопок"->"Новая группа кнопок". В коде уже использовать указатель на buttonGroup, создать слот в главном окне типа on_buttonGroup_buttonClicked(QAbstractButton * button).

А можно поподробнее о группе кнопок? Пожалуйста. Я не нашел в дизайнере такой штуки. Вот я выделил 5 QPushButton, а дальше что сделать? При нажатии на правую клавишу я вижу следующее меню:
Цитата
Change Text
Change objectName
Change toolTip
Change whatsThis
Change styleSheet

Promote to ...

Cut
Copy
Paste
Select All
Delete

Lay Out


Заранее спасибо за ответ....
Andrewshkovskii
Странно..а Qt какой версии?Нажмите для просмотра прикрепленного файла
AD
Qt 4.3.2
Andrewshkovskii
Юрий за спам нас перенес..:))
Странно, насколько я понял из асиста, эта возможность была уже с версии 4.1. Хотя бы вот по этому
Цитата
QAbstractButton * QButtonGroup::button ( int id ) const
Returns the button with the specified id, or 0 if no such button exists.

This function was introduced in Qt 4.1.
Litkevich Yuriy
AD, в Дизайнере 4.3.х нет такой возможности
AD
То есть только самому через QButtonGroup?

Ассистент:
Цитата
The QButtonGroup class provides a container to organize groups of button widgets.
QButtonGroup provides an abstract container into which button widgets can be placed. It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group.
An exclusive button group switches off all checkable (toggle) buttons except the one that was clicked. By default, a button group is exclusive. The buttons in a button group are usually checkable QPushButton's, QCheckBoxes (normally for non-exclusive button groups), or QRadioButtons. If you create an exclusive button group, you should ensure that one of the buttons in the group is initially checked; otherwise, the group will initially be in a state where no buttons are checked.
A button is added to the group with addButton(). It can be removed from the group with removeButton(). If the group is exclusive, the currently checked button is available as checkedButton(). If a button is clicked the buttonClicked() signal is emitted. For a checkable button in an exclusive group this means that the button was checked. The list of buttons in the group is returned by buttons().
In addition, QButtonGroup can map between integers and buttons. You can assign an integer id to a button with setId(), and retrieve it with id(). The id of the currently checked button is available with checkedId(), and there is an overloaded signal buttonClicked() which emits the id of the button. The purpose of the mapping mechanism is to simplify the representation of enum values in a user interface.

SABROG
Да, но тогда с методом void QButtonGroup::addButton ( QAbstractButton * button ) снова здравствуйте китайцы. Можно конечно через такой код сделать и в цикле их добавлять:

QList<QPushButton *> allPButtons = parentWidget.findChildren<QPushButton *>();


Только надо как-то будет котлеты от мух отделить. С другой стороны можно вообще динамически создать кнопки от A до Z. Опять же в цикле, 26 итераций.
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.