Просмотр сообщений
|
Страниц: 1 [2] 3 4 ... 12
|
16
|
Qt / Вопросы новичков / Re: Передача параметра в слот
|
: Октябрь 20, 2017, 22:22
|
Можно сделать через setData примерно так. Компилятора под рукой нет, так что возможны ошибки. { QAction* act1 = new QAction("Белый", mainFrames[i][j][k]); act1->setData( "white" ); connect(act1 , SIGNAL(triggered()), this, SLOT(changeColor()));
QAction* act2 = new QAction("Оранжевый", mainFrames[i][j][k]); act2->setData( "orange" ); connect(act2 , SIGNAL(triggered()), this, SLOT(changeColor()));
QAction* act3 = new QAction("Зеленый", mainFrames[i][j][k]); act3->setData( "green" ); connect(act3 , SIGNAL(triggered()), this, SLOT(changeColor()));
QAction* act4 = new QAction("Красный", mainFrames[i][j][k]); act4->setData( "red" ); connect(act4 , SIGNAL(triggered()), this, SLOT(changeColor()));
QAction* act5 = new QAction("Синий", mainFrames[i][j][k]); act5->setData( "blue" ); connect(act5 , SIGNAL(triggered()), this, SLOT(changeColor()));
QAction* act6 = new QAction("Желтый", mainFrames[i][j][k]); act6->setData( "yellow" ); connect(act6 , SIGNAL(triggered()), this, SLOT(changeColor()));
mainFrames[i][j][k]->addAction(act1); mainFrames[i][j][k]->addAction(act2); mainFrames[i][j][k]->addAction(act3); mainFrames[i][j][k]->addAction(act4); mainFrames[i][j][k]->addAction(act5); mainFrames[i][j][k]->addAction(act6); mainFrames[i][j][k]->setContextMenuPolicy(Qt::ActionsContextMenu); }
void MainWindow::changeColor() { // Находим action, который отправил сигнал QAction* action = qobject_cast<QAction*>(QObject::sender()); // Находим заложенный в него цвет QString color = action->data().toString(); // Находим виджет-родитель QFrame* frame = qobject_cast<QFrame*>(action->parent()); // Устанавливаем стиль color = color.prepend("background-color: "); frame ->setStyleSheet(color); }
|
|
|
19
|
Qt / Model-View (MV) / Re: Иерархическая модель, drag-n-drop
|
: Август 10, 2017, 19:56
|
А почему вы не хотите переопределять методы mimeData и canDropMime? Так же проще будет. В стандартной имплементации копируются роли итемов только до Qt::UserRole. Если ваша роль больше или равна Qt::UserRole, она не будет скопирована. Смотрите методы void QAbstractItemModel::encodeData(const QModelIndexList &indexes, QDataStream &stream) const bool QAbstractItemModel::decodeData(int row, int column, const QModelIndex &parent, QDataStream &stream) QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const например, тут : http://code.qt.io/cgit/qt/qt.git/plain/src/corelib/kernel/qabstractitemmodel.cppВот код который определяет роли для копирования: QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const { QMap<int, QVariant> roles; for (int i = 0; i < Qt::UserRole; ++i) { QVariant variantData = data(index, i); if (variantData.isValid()) roles.insert(i, variantData); } return roles; }
|
|
|
25
|
Qt / Model-View (MV) / Re: QStandardItemModel. EditRole, DisplayRole - как хранить разные данные в них?
|
: Март 02, 2017, 09:14
|
Qt::DisplayRole 0 The key data to be rendered in the form of text. (QString) Qt::EditRole 2 The data in a form suitable for editing in an editor. (QString)
Допустим, вы выводите в таблице зарплату сотрудника. Qt::DisplayRole (QString) : "1000 р." Qt::EditRole (int для редактирования) : 1000
В зависимости от типа данных в Qt::EditRole будет создаваться соответствующий делегат для редактирования этих данных.
|
|
|
29
|
Программирование / С/C++ / Re: Почему образуются "лишние" байты при чтении из stringstream?
|
: Январь 08, 2017, 20:57
|
Может быть поэтому: std::istream::read istream& read (char* s, streamsize n); If the input sequence runs out of characters to extract (i.e., the end-of-file is reached) before n characters have been successfully read, the array pointed to by s contains all the characters read until that point, and both the eofbit and failbit flags are set for the stream.
|
|
|
Страниц: 1 [2] 3 4 ... 12
|
|
|