我刚刚开始学习Qt,我计划写一个数独程序。我已经使用QPainter绘制了9*9地图,但是我不能在它的grids.How中输入数字来解决这个问题?如果我想要一个新的9*9地图,其中包含一些不能在其中修改的数字,并且在其他网格中我可以自由输入数字,我应该怎么做?非常感谢!
发布于 2019-03-16 02:20:30
我也会使用QLineEdits,然后禁用预先设置好的。
这将为您提供一个起点(注意:在本例中,我向mainWindow添加了一个简单的gridLayout ):
// 2D list of all line-edits - in case you want to access the elements later
QList<QList<QLineEdit*>> numEdits;
QValidator *validator = new QIntValidator(1, 9, this);
for (int idx = 0; idx < 9; ++idx) {
numEdits.append(QList<QLineEdit*>());
for (int jdx = 0; jdx < 9; ++jdx) {
QLineEdit *item = new QLineEdit(this);
item->setValidator(validator);
// for pre-set values
item->setEnabled(false);
ui->gridLayout->addWidget(item, idx, jdx);
numEdits[idx].append(item);
}
}https://stackoverflow.com/questions/55184295
复制相似问题