qt - QTableView's cells are empty, but headers show up -
I created a representative pretty copied from QT's spin box representative example and I'm trying to fill a QTableView . However, I am getting a strange problem where table headers are shown but cells are empty and can not be clicked address to representatives: DoubleSpinBoxDelegate :: DoubleSpinBoxDelegate (QObject * parent): QItemDelegate (parent) {} QWidget * DoubleSpinBoxDelegate: : createEditor (QWidget * parent, const QStyleOptionViewItem & amp; alternative, And the function I'm calling in the form creator Your representative is allocated on the stack, and it has been removed after it exits from the scope. Instead, make your representative new.
#include "double_spinbox_delegate.h" Const QModelIndex and index) const {QDoubleSpinBox * editor = new QDoubleSpinBox (guardian); Editor & gt; SetValue (0); // if (index.column () == 0) {// editor-> Set minimum (0); // editor-> Setmaxime (255); //} // else {// editor-> Set minimum (0); // editor-> Set (1); // Return Editor; } Zero DoubleSpinBoxDelegate :: setEditorData (QWidget * Editor, constant QModelIndex & Index) constants {double value = index.model () -> Data (index, QT :: EditRole) .toDouble (); QDoubleSpinBox * Double SpinBox = Fixed_cast & lt; QDoubleSpinBox * & gt; (Editor); DoubleSpinBox-> SetValue (value); } Void DoubleSpinBoxDelegate :: setModelData (QWidget * editor, QAbstractItemModel * model, constant QModelIndex & amp; index) const {QDoubleSpinBox * doubleSpinBox = static_cast & LT; QDoubleSpinBox * & gt; (Editor); DoubleSpinBox-> InterpretText (); Double value = double spin box- & gt; Values (); Model- & gt; Setdata (index, value, qt :: editor); } Void DoubleSpinBoxDelegate :: updateEditorGeometry (QWidget * editor, constant QStyleOptionViewItem & amp; alternative, constant QModelIndex & amp; index) const {Editor & gt; SetGeometry (option.rect); }
void MainWindow :: InitializeColorTable () {QTableView * tableColor = UI- & gt; TableColor; QStandardItemModel * Model = New QStandardItemModel (4, 4, ui- & gt; Table Collar); // QStandardItemModel * Model = this- & gt; Color Tables Module TableColor-> SetModel (model); DoubleSpinBox undisputed representative; TableColor-> SetItemDelegate (& amp; Representative); Model- & gt; Set Horizontal Header Labels (Qestring List) & lt; & Lt; Tr ("value") & lt; Tr ("R") & lt; & Lt; Tr ("G") & lt; & Lt; Tr ("B")); (Int Call = 0; call and Leftida; model & gt; column (); ++ Cola) {Kyuemdel index index = model (at row = 0; row & lt; model & gt; Panktikota (); ++ row) - & gt; Index (row, call, cumulode index ()); Model- & gt; SetData (index, quewrient (+ + + +0 +0) * (cola + 1.0)), QT :: editorial;}}}
Double spinbox representative representative; TableColor-> setItemDelegate (& amp; Representative);
Comments
Post a Comment