本文整理汇总了C++中QAbstractItemModel::flags方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractItemModel::flags方法的具体用法?C++ QAbstractItemModel::flags怎么用?C++ QAbstractItemModel::flags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractItemModel
的用法示例。
在下文中一共展示了QAbstractItemModel::flags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flags
Qt::ItemFlags TodoNode::flags(int column) const
{
if (m_rowSourceIndex.isValid()) {
QAbstractItemModel *model = const_cast<QAbstractItemModel*>(m_rowSourceIndex.model());
return model->flags(m_rowSourceIndex.sibling(m_rowSourceIndex.row(), column));
} else {
return m_flags;
}
}
示例2: updateAllRows
void QtlCheckableHeaderView::updateAllRows()
{
QAbstractItemModel* model = this->model();
if (model != 0) {
const Qt::CheckState state = (_checkState == Qt::Unchecked) ? Qt::Unchecked : Qt::Checked;
for (int row = 0; row < model->rowCount(); row++) {
const QModelIndex index = model->index(row, 0);
if (index.isValid() && (model->flags(index) & Qt::ItemIsUserCheckable) != 0) {
model->setData(index, state, Qt::CheckStateRole);
}
}
}
}
示例3: paintSection
void QtlCheckableHeaderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
{
// Invoke the superclass to do the main job.
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
// We need to paint the checkbox when we are in section 0 only.
// We also need a model (sanity check).
QAbstractItemModel* model = this->model();
if (model == 0 || logicalIndex != 0) {
return;
}
// Count the total number of checkable and checked items in the first column.
int checkableCount = 0;
int checkedCount = 0;
for (int row = 0; row < model->rowCount(); row++) {
const QModelIndex index = model->index(row, 0);
if (index.isValid() && (model->flags(index) & Qt::ItemIsUserCheckable) != 0) {
checkableCount++;
const Qt::CheckState state= model->data(index, Qt::CheckStateRole).value<Qt::CheckState>();
if (state != Qt::Unchecked) {
checkedCount++;
}
}
}
// Final position and size of the checkbox.
QStyleOptionButton option;
option.rect = checkBoxRect(rect.topLeft());
option.state |= QStyle::State_Enabled;
// Compute the new check state.
Qt::CheckState newCheckState = _checkState;
if (_forceCheck) {
// Force either checked or unchecked. Do it once only.
_forceCheck = false;
if (_checkState == Qt::Unchecked) {
option.state |= QStyle::State_Off;
newCheckState = Qt::Unchecked;
}
else {
option.state |= QStyle::State_On;
newCheckState = Qt::Checked;
}
}
else if (checkedCount == 0) {
option.state |= QStyle::State_Off;
newCheckState = Qt::Unchecked;
}
else if (checkedCount < checkableCount) {
option.state |= QStyle::State_NoChange;
newCheckState = Qt::PartiallyChecked;
}
else if (checkedCount == checkableCount) {
option.state |= QStyle::State_On;
newCheckState = Qt::Checked;
}
else {
// Should not get there.
Q_ASSERT(false);
option.state |= QStyle::State_None;
}
// Now draw the checkbox.
style()->drawControl(QStyle::CE_CheckBox, &option, painter);
// Finally report change in state.
if (_checkState != newCheckState) {
_checkState = newCheckState;
const_cast<QtlCheckableHeaderView*>(this)->processCheckStateChanged();
}
}
示例4: NewWidget
QWidget *OBSPropertiesView::AddList(obs_property_t *prop, bool &warning)
{
const char *name = obs_property_name(prop);
QComboBox *combo = new QComboBox();
obs_combo_type type = obs_property_list_type(prop);
obs_combo_format format = obs_property_list_format(prop);
size_t count = obs_property_list_item_count(prop);
int idx = -1;
for (size_t i = 0; i < count; i++)
AddComboItem(combo, prop, format, i);
if (type == OBS_COMBO_TYPE_EDITABLE)
combo->setEditable(true);
string value = from_obs_data(settings, name, format);
if (format == OBS_COMBO_FORMAT_STRING &&
type == OBS_COMBO_TYPE_EDITABLE)
combo->lineEdit()->setText(QT_UTF8(value.c_str()));
else
idx = combo->findData(QT_UTF8(value.c_str()));
if (type == OBS_COMBO_TYPE_EDITABLE)
return NewWidget(prop, combo,
SIGNAL(editTextChanged(const QString &)));
if (idx != -1)
combo->setCurrentIndex(idx);
if (obs_data_has_autoselect_value(settings, name)) {
string autoselect =
from_obs_data_autoselect(settings, name, format);
int id = combo->findData(QT_UTF8(autoselect.c_str()));
if (id != -1 && id != idx) {
QString actual = combo->itemText(id);
QString selected = combo->itemText(idx);
QString combined = QTStr(
"Basic.PropertiesWindow.AutoSelectFormat");
combo->setItemText(idx,
combined.arg(selected).arg(actual));
}
}
QAbstractItemModel *model = combo->model();
warning = idx != -1 &&
model->flags(model->index(idx, 0)) == Qt::NoItemFlags;
WidgetInfo *info = new WidgetInfo(this, prop, combo);
connect(combo, SIGNAL(currentIndexChanged(int)), info,
SLOT(ControlChanged()));
children.push_back(std::move(unique_ptr<WidgetInfo>(info)));
/* trigger a settings update if the index was not found */
if (idx == -1)
info->ControlChanged();
return combo;
}