在QItemEditorCreatorBase中使用后找回QWidget
Get back QWidget after using in QItemEditorCreatorBase
本文关键字:QWidget QItemEditorCreatorBase 更新时间:2023-10-16
我有一个数字编辑器可以扩展QSpinBox
NumericEditor::NumericEditor(QWidget *widget): QSpinBox(widget)
我使用此编辑器编辑QTableWidget
中的类型QVariant::Int
QItemEditorCreatorBase *numericEditor = new QStandardItemEditorCreator<NumericEditor>();
factory->registerEditor(QVariant::Int, numericEditor);
数据正常输入表格。忽略"颜色"一词的用法。它基于颜色编辑器示例。
QTableWidgetItem *nameItem2 = new QTableWidgetItem(QString("label2"));
QTableWidgetItem *colorItem2 = new QTableWidgetItem();
colorItem2->setData(Qt::DisplayRole, QVariant(int(4)));
table->setItem(1, 0, nameItem2);
table->setItem(1, 1, colorItem2);
数字显示框,并在 QTableWidget 中正常工作。
我的愿望是访问表在编辑单元格时使用的 QSpinBox 实例QVariant::Int
以便我可以设置最小值和最大值。
我该怎么做?
您可以使用 QTableWidget::setItemDelegateForColumn
在列上安装委托,当打开编辑器时,将调用其createEditor
方法。
class MyDelegate : public QStyledItemDelegate {
public:
QWidget *createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const {
// You could create the widget from scratch or call
// the base function which will use the QItemEditor you already wrote
QWidget * editor = QStyledItemDelegate::createEditor(parent, option, index);
// do whatever you need to do with the widget
editor->setProperty("minimum", 100);
editor->setProperty("maximum", 100);
return editor;
}
};
相关文章:
- 如何在QT Creator上将QWidget声明为继承类的对象
- QWidget::p aintEngine:不应再在 QTreeWidget 派生类中调用
- 将一个 QWidget 链接到另一个新创建的 QWidget
- 为什么 isVisible 在 QWidget 孩子中不起作用
- 如何声明全局QWidget?
- QWidget UI 在使用 QQuickWidget 时冻结
- "(QWidget* pobj=0)"和"(QWidget* pwgt/*=0/)&quo
- qt QWidget::closeEvent link issue
- 如何在QMdiSubWindow关闭后删除QWidget
- 如何在QGraphicsView中移动QWidget?
- QPainter的QWidget滚动条
- 在类中创建 QWidget
- 在另一个小部件中更改QWidget的背景颜色
- 使用 QMediaPlayer 时出现"QWidget::paintEngine: Should no longer be called"
- QWidget收听其他QWidgets事件
- 为提升的小部件设置父 QWidget
- 如何制作可以缩放和绘制的画布QWidget?
- 在 QWidget 中的 QGraphicsScene 中绘制
- 如何将不在 QT 全局范围内的函数附加到 Qwidget 上
- 无法在 qt 中为 QWidget 中的派生类设置样式表