Форум программистов, компьютерный форум, киберфорум
C++ Qt
Войти
Регистрация
Восстановить пароль
Другие темы раздела
C++ Qt Добавить к QChartView поля для ввода День добрый. Делаю вывод графиков, подскажите, пожалуйста - как можно сделать QchartView с полями для ввода. Графики на основное окно добавляю так: QGridLayout* glayout = new QGridLayout(this); //grid - т.к. будет 4 графика со схожим функционалом glayout->setMargin(4); glayout->setSpacing(4); ui->centralWidget->setLayout(glayout); https://www.cyberforum.ru/ qt/ thread2649026.html dll для виджета, debug, release конфигурации C++ Qt
Добрый день! Написал DLL для своего виджета. При подключении полученной DLL к приложениям - для debug конфигурации необходима debug версия DLL, а, соответственно, для release конфигурации нужна release версия DLL, иначе при запуске приложение выдает ошибки. Существует ли возможность создать универсальную DLL виджета, корректно работающую одновременно с debug и release конфигурациями...
C++ Qt Как ставить поток на паузу? Как ставить функцию, выполняющуюся в потоке, на паузу по нажатию кнопки? Писал программу в qt creator, чтобы кнопки можно было делать. Я сделал кнопочку, которая собирает данные с полей для ввода и отправляет их в функцию расчёта, отправляет в другой поток (функция очень большая и долго считающая). Мне нужно, чтобы можно было прерывать выполнение этой функции в любой момент (нажимать на паузу).... https://www.cyberforum.ru/ qt/ thread2647818.html C++ Qt QScroll менять только руками Привет. Есть ли какой-то флаг, чтобы скролл не менял свое положение относительно изменения модели, а только руками? Проще говоря- пользователь поставил скролл посередине в QTableView, вью удаляет\добавляет строки через QSortFilterProxyModel- нужно, чтобы скролл никуда не ездил программно, а оставался вот на этих условных 50% (значение может быть разным, исходя из того, в каком положении... https://www.cyberforum.ru/ qt/ thread2647424.html
QGraphicsScene и QML C++ Qt
Добрый день. Ищу работу программистом С++(Qt) - новичок. Учу Qt, дошел до QML. Все что связано с графикой(QGraphicsScene, QGraphicsView...) пропустил. присылали тестовое задание по QML и в основном по QWidget, из-за этого делал акцент на него. Но не давно прислали задание по использованию классов QGraphicsScene, QGraphicsView. Вопрос. На данный момент необходимо знать классы QGraphicsScene,...
C++ Qt Добавление элемента массива в существующий JSON файл Имеется JSON файл (прим. ниже). Задача, получить массив по имени, и добавить в него 1 элемент, без создания копии в конце файла (как у меня сейчас получается). { "wears":, "employees": } Можно конечно разделить объекты employees и wears по отдельным файлам, и каждый раз перед обновлением файла, полностью его стирать и полностью записывать, но мне кажется, что должно быть какое-то... https://www.cyberforum.ru/ qt/ thread2647140.html
C++ Qt Работа с кнопками через их текст Pushbutton.Caption.IsText== Дана данная строчка кода для работы с текстом на кнопке ( во время действия программы, в ней, на кнопках меняется текст. случайным образом. Мне же нужно чтобы можно было обращаться по кнопке не через ее номер, а через текст который на ней есть ( там только цифры, собственно ) ) однако она не работает ( возможно я не использовал что нибудь…. однако почему то в инете не... https://www.cyberforum.ru/ qt/ thread2647130.html классы и определения в этих классах C++ Qt
Добрый день Столкнулся с невероятно грустной проблемой. Рабочая до некоторого момента прога перестала выполнять свои функции. Даже более того... Начала появляться одна страшная ошибка: 'buttons' was not declared in this scope. при самой функции int r = 0 void MainWindow::on_pushButton_4_clicked() { buttons.append(ui->pushButton); buttons.append(ui->pushButton_2); ...
C++ Qt Пауза QNAM Приветствую, как реализовать паузу и возобновление при скачивание? Читай документацию и не нашел ни единого намека. https://www.cyberforum.ru/ qt/ thread2646120.html C++ Qt QSqlQuery Segmentation fault Доброго времени суток! QList<Record> SqlUtilities::getListOfRecords() { QSqlQuery query(db); query.prepare("..."); query.exec(); QList<Record> list; Record record; https://www.cyberforum.ru/ qt/ thread2645988.html
C++ Qt Контейнер Queue
Такой вопрос, как мне считать числовую строку по типу "1 2 3 4 5 6" с lineEdit и записать эти числа в контейнер queue для подальшей роботы с ним?
C++ Qt Как в Qcustomplot сгладить график,построенный по точкам? Здравствуйте. Подскажите пожалуйста, как в qcustomplot сделать так, чтобы график отображался плавным, а не просто как угловатое соединение точек линиями? График строится по набору точек. https://www.cyberforum.ru/ qt/ thread2645134.html
Эксперт по математике/физикеЭксперт С++
2044 / 1363 / 393
Регистрация: 16.05.2013
Сообщений: 3,498
Записей в блоге: 6
22.05.2020, 12:42 0

Перенос текста в ячейке - C++ Qt - Ответ 14570585

22.05.2020, 12:42. Показов 1385. Ответов 3
Метки (Все метки)

Ответ

Вот Вам пример полного кода делегата из одного проекта. Выделять суть было лень, так что разбирайтесь:
C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef OGESNDELEGATE_H
#define OGESNDELEGATE_H
 
#include <QStyledItemDelegate>
/**
  ******************************************************************************
 
  ******************************************************************************
*/
namespace cassandra {
/**
  ******************************************************************************
 
  ******************************************************************************
*/
class oGesnDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    explicit oGesnDelegate(QObject * parent = Q_NULLPTR);
public slots:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    void mf_remove_from_cash_type_work(const QModelIndex& index);
public:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    virtual QSize sizeHint(
            const QStyleOptionViewItem & option,
            const QModelIndex & index) const;
public:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    virtual void paint(
            QPainter * painter, const
            QStyleOptionViewItem & option,
            const QModelIndex & index) const;
private:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    void mf_paint_section(
            QPainter * painter,
            const QStyleOptionViewItem & option,
            const QModelIndex & index) const;
private:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    QString mf_insert_space_to_string(QString& value) const;
private:
    /**
      **************************************************************************
 
      **************************************************************************
    */
    mutable QHash<QModelIndex, QVector<int>> mv_map_sections_word_width;
    mutable QHash<QModelIndex, QVector<int>> mv_map_position_word_width;
    mutable QHash<QModelIndex, QVector<int>> mv_map_position_type_work;
    mutable QHash<QModelIndex, int> mv_map_label_word_width;
};
}
#endif // OGESNDELEGATE_H
C++ (Qt)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#include <QApplication>
#include <QPainter>
#include <QDebug>
#include <QTreeView>
#include <QHeaderView>
#include "oGesnDelegate.h"
#include "cGesnRecord.h"
#include "wGesnView.h"
#include "constants.h"
/**
  ******************************************************************************
 
  ******************************************************************************
*/
cassandra::oGesnDelegate::oGesnDelegate(QObject *parent) :
    QStyledItemDelegate(parent),
    mv_map_sections_word_width(),
    mv_map_position_word_width(),
    mv_map_position_type_work(),
    mv_map_label_word_width()
{
}
/**
  ******************************************************************************
 
  ******************************************************************************
*/
void cassandra::oGesnDelegate::paint(
        QPainter * painter,
        const QStyleOptionViewItem & option,
        const QModelIndex & index) const {
 
    int t_int_record_type =
            index.data(cassandra::ns_gesn_role::c_int_type_role).toInt();
 
    switch (t_int_record_type) {
    case cassandra::ns_gesn_record_type::c_int_none:
    case cassandra::ns_gesn_record_type::c_int_branch:
    case cassandra::ns_gesn_record_type::c_int_section:
    case cassandra::ns_gesn_record_type::c_int_subsection:
    case cassandra::ns_gesn_record_type::c_int_table:
    {
        if(option.state & QStyle::State_Selected) {
            painter->fillRect(
                        option.rect,
                        QBrush(
                            QColor(
                                cassandra::nsg_colors::c_int_selected_section_r,
                                cassandra::nsg_colors::c_int_selected_section_g,
                                cassandra::nsg_colors::c_int_selected_section_b)));
        }
        else if(t_int_record_type
                == cassandra::ns_gesn_record_type::c_int_table) {
            painter->fillRect(
                        option.rect,
                        QBrush(
                            QColor(
                                cassandra::nsg_colors::c_int_section_r,
                                cassandra::nsg_colors::c_int_section_g,
                                cassandra::nsg_colors::c_int_section_b)));
        }
 
        mf_paint_section(painter, option, index);
    } break;
    case cassandra::ns_gesn_record_type::c_int_position:
    {
        if(option.state & QStyle::State_Selected) {
            painter->fillRect(
                        option.rect,
                        QBrush(
                            QColor(
                                cassandra::nsg_colors::c_int_selected_position_r,
                                cassandra::nsg_colors::c_int_selected_position_g,
                                cassandra::nsg_colors::c_int_selected_position_b)));
        }
 
        switch (index.column()) {
        case cassandra::ns_gesn_column_number::c_int_rationale:
        {
            QList<QVariant> t_list = index.data().toList();
 
            Q_ASSERT(t_list.size() >= 2);
 
            painter->save();
            painter->setClipRect(option.rect);
 
            QString t_string_abbreviation;
 
            QFont t_font = painter->font();
            if(t_list.at(0).canConvert(QMetaType::QString)) {
                t_string_abbreviation = t_list.at(0).toString();
 
                t_font.setBold(true);
                painter->setFont(t_font);
 
                painter->drawText(
                            option.rect.adjusted(
                                cassandra::nsg_text_positioning::c_int_indentation,
                                0,
                                0,
                                0),
                            Qt::AlignTop | Qt::AlignLeft,
                            t_string_abbreviation);
            }
 
            int t_int_label_length =
                    QFontMetrics(painter->font()).width(t_string_abbreviation) +
                    cassandra::nsg_text_positioning::c_int_indentation +
                    cassandra::nsg_text_positioning::c_int_indentation;
 
            if(t_list.at(1).canConvert(QMetaType::QString)) {
                t_font = painter->font();
                t_font.setBold(false);
                painter->setFont(t_font);
 
                painter->drawText(
                            option.rect.adjusted(
                                t_int_label_length,
                                0,
                                0,
                                0),
                            Qt::AlignTop | Qt::AlignLeft,
                            t_list.at(1).toString());
            }
 
            painter->restore();
        } break;
        case cassandra::ns_gesn_column_number::c_int_content:
        {
            QTextOption t_text_option(Qt::AlignLeft | Qt::AlignTop);
            t_text_option.setWrapMode(QTextOption::WordWrap);
 
            painter->drawText(
                        option.rect.adjusted(
                            cassandra::nsg_text_positioning::c_int_indentation,
                            0,
                            -cassandra::nsg_text_positioning::c_int_indentation,
                            0),
                        index.data(Qt::DisplayRole).toString(),
                        t_text_option);
 
        } break;
        case cassandra::ns_gesn_column_number::c_int_unit:
        {
            QTextOption t_text_option(Qt::AlignHCenter | Qt::AlignTop);
            t_text_option.setWrapMode(QTextOption::WordWrap);
 
            painter->drawText(
                        option.rect.adjusted(
                            0,
                            0,
                            0,
                            0),
                        index.data(Qt::DisplayRole).toString(),
                        t_text_option);
        } break;
        case cassandra::ns_gesn_column_number::c_int_builder_rank:
        case cassandra::ns_gesn_column_number::c_int_builder_expenses:
        case cassandra::ns_gesn_column_number::c_int_machinist_expenses:
        {
            QTextOption t_text_option(Qt::AlignRight | Qt::AlignTop);
 
            painter->drawText(
                        option.rect.adjusted(
                            0,
                            0,
                            -cassandra::nsg_text_positioning::c_int_indentation,
                            0),
                        index.data(Qt::DisplayRole).toString(),
                        t_text_option);
        } break;
        }
    } break;
    }
 
    painter->save();
    QPen t_pen = QApplication::palette().color(QPalette::Mid);
    painter->setPen(t_pen);
    painter->drawRect(option.rect.adjusted(-1, 0, -1, 0));
    painter->restore();
}
/**
  ******************************************************************************
 
  ******************************************************************************
*/
void cassandra::oGesnDelegate::mf_paint_section(
        QPainter * painter,
        const QStyleOptionViewItem & option,
        const QModelIndex & index) const {
 
    QRect t_rect =
            option.rect.adjusted(
                0,
                0,
                cassandra::ns_gesn_row_heigth::c_int_default -
                option.rect.width(),
                cassandra::ns_gesn_row_heigth::c_int_default -
                option.rect.height()).marginsRemoved(
                QMargins(
                    cassandra::ns_global_margin::c_int_collapse_expand_icon,
                    cassandra::ns_global_margin::c_int_collapse_expand_icon,
                    cassandra::ns_global_margin::c_int_collapse_expand_icon,
                    cassandra::ns_global_margin::c_int_collapse_expand_icon));
 
    QTreeView * t_tree_view = qobject_cast<QTreeView*>(parent());
    if(t_tree_view) {
        if(t_tree_view->isExpanded(index)) {
            painter->drawImage(
                        t_rect,
                        QImage(
                            QString(":/image/img_arrow_down.png")));
        }
        else {
            painter->drawImage(
                        t_rect,
                        QImage(
                            QString(":/image/img_arrow_up.png")));
        }
    }
 
    QList<QVariant> t_list = index.data().toList();
 
    Q_ASSERT(t_list.size() >= 3);
 
    painter->save();
    QString t_string_section;
    QFont t_font = painter->font();
    if(t_list.at(0).canConvert(QMetaType::QString)
            && t_list.at(1).canConvert(QMetaType::QString)) {
        QString t_string_category = t_list.at(0).toString();
        QString t_string_number   = t_list.at(1).toString();
 
        if(!t_string_category.isEmpty() && t_string_number.isEmpty()) {
            t_string_section = QString("%1:").arg(t_string_category);
        }
        else if(!t_string_category.isEmpty() && !t_string_number.isEmpty()) {
            t_string_section = QString("%1 %2.").arg(
                        t_string_category).arg(
                        t_string_number);
        }
 
        if(!t_string_section.isEmpty()) {
            painter->setClipRect(option.rect);
            t_font.setBold(true);
            painter->setFont(t_font);
 
            painter->drawText(
                        option.rect.adjusted(
                            cassandra::ns_gesn_row_heigth::c_int_default,
                            cassandra::nsg_text_positioning::c_int_indentation,
                            0,
                            0),
                        Qt::AlignTop | Qt::AlignLeft,
                        t_string_section);
        }
    }
 
    int t_int_date_label_length = mv_map_label_word_width[index];
 
    if(t_list.at(2).canConvert(QMetaType::QString)) {
        t_font = painter->font();
        t_font.setBold(false);
        painter->setFont(t_font);
 
        QTextOption t_text_option(Qt::AlignLeft | Qt::AlignTop);
        t_text_option.setWrapMode(QTextOption::WordWrap);
 
        painter->drawText(
                    option.rect.adjusted(
                        t_int_date_label_length,
                        cassandra::nsg_text_positioning::c_int_indentation,
                        0,
                        0),
                    t_list.at(2).toString(),
                    t_text_option);
    }
 
    painter->restore();
}
/**
  ******************************************************************************
 
  ******************************************************************************
*/
QString cassandra::oGesnDelegate::mf_insert_space_to_string(
        QString& value) const {
 
    QString t_string_value = value;
 
    int t_int_pos = t_string_value.indexOf(QChar(','));
    t_int_pos -= 3;
    while (t_int_pos > 0) {
        t_string_value.insert(t_int_pos, QChar(' '));
        t_int_pos -= 3;
    }
 
    return t_string_value;
}
/**
  ******************************************************************************
 
  ******************************************************************************
*/
QSize cassandra::oGesnDelegate::sizeHint(
        const QStyleOptionViewItem & option,
        const QModelIndex & index) const {
 
    QSize t_size;
 
    int t_int_record_type =
            index.data(cassandra::ns_gesn_role::c_int_type_role).toInt();
 
    switch (t_int_record_type) {
    case cassandra::ns_gesn_record_type::c_int_none:
    case cassandra::ns_gesn_record_type::c_int_branch:
    case cassandra::ns_gesn_record_type::c_int_section:
    case cassandra::ns_gesn_record_type::c_int_subsection:
    case cassandra::ns_gesn_record_type::c_int_table:
    {
        int t_int_column_width = -1;
 
        QTreeView * t_tree_view = qobject_cast<QTreeView*>(parent());
        if(t_tree_view) {
            t_int_column_width =
                    t_tree_view->header()->sectionPosition(
                        cassandra::ns_gesn_column_number::c_int_machinist_expenses) +
                    t_tree_view->header()->sectionSize(
                        cassandra::ns_gesn_column_number::c_int_machinist_expenses);
        }
 
        int t_int_width_space = option.fontMetrics.width(QChar(' '));
 
        int t_int_date_label_length = cassandra::ns_gesn_row_heigth::c_int_default;
 
 
        if(!mv_map_label_word_width.contains(index)) {
            QFont t_font = option.font;
            t_font.setBold(true);
 
            QFontMetrics t_font_metrics(t_font);
 
            QList<QVariant> t_list = index.data().toList();
 
            Q_ASSERT(t_list.size() >= 3);
 
            QString t_string_section;
            if(t_list.at(0).canConvert(QMetaType::QString)
                    && t_list.at(1).canConvert(QMetaType::QString)) {
                QString t_string_category = t_list.at(0).toString();
                QString t_string_number   = t_list.at(1).toString();
 
                if(!t_string_category.isEmpty() && t_string_number.isEmpty()) {
                    t_string_section = QString("%1.").arg(t_string_category);
                }
                else if(!t_string_category.isEmpty() && !t_string_number.isEmpty()) {
                    t_string_section = QString("%1 %2.").arg(
                                t_string_category).arg(
                                t_string_number);
                }
            }
 
            if(!t_string_section.isEmpty()) {
                t_int_date_label_length +=
                        t_font_metrics.width(t_string_section) +
                        cassandra::nsg_text_positioning::c_int_indentation;
            }
 
            mv_map_label_word_width[index] = t_int_date_label_length;
 
 
 
            QStringList t_string_list_words =
                    t_list.at(2).toString().split(QRegExp("\\s+|-"));
 
            int t_int_words_count = t_string_list_words.size();
 
            QVector<int> t_vector_words_width(t_int_words_count);
            for (int i = 0; i < t_int_words_count; ++i) {
                int t_int_current_word =
                        option.fontMetrics.width(t_string_list_words[i]);
                t_vector_words_width.append(t_int_current_word);
            }
 
            mv_map_sections_word_width[index] = t_vector_words_width;
        }
 
        t_int_column_width -=
                mv_map_label_word_width[index] +
                cassandra::nsg_text_positioning::c_int_indentation;
 
        QVector<int> t_vector_words_width = mv_map_sections_word_width[index];
 
        int t_int_words_count = t_vector_words_width.size();
        int t_int_current_string_width = 0;
        int t_int_string_count = 0;
        int t_int_words_count_in_string = 0;
 
        for (int i = 0; i < t_int_words_count; ++i) {
            if(t_vector_words_width.at(i) == 0) {
                continue;
            }
 
            if(t_int_current_string_width + t_vector_words_width.at(i)
                    > t_int_column_width) {
 
                if(t_int_words_count_in_string != 0) {
                    t_int_current_string_width =
                            t_vector_words_width.at(i) + t_int_width_space;
                    t_int_words_count_in_string = 1;
                }
 
                ++t_int_string_count;
            }
            else {
                t_int_current_string_width +=
                        t_vector_words_width.at(i) + t_int_width_space;
 
                ++t_int_words_count_in_string;
            }
        }
 
        int t_int_height =
                (t_int_string_count + 1) * option.fontMetrics.height();
 
        if(t_int_height >= cassandra::ns_gesn_row_heigth::c_int_default) {
            t_size.setHeight(t_int_height + 2);
        }
        else {
            t_size.setHeight(cassandra::ns_gesn_row_heigth::c_int_default);
        }
    } break;
    case cassandra::ns_gesn_record_type::c_int_position:
    {
        if(index.column() == cassandra::ns_gesn_column_number::c_int_content) {
 
            int t_int_column_width = -1;
            QTreeView * t_tree_view = qobject_cast<QTreeView*>(parent());
            if(!t_tree_view) {
                t_int_column_width =
                        cassandra::ns_gesn_column_number::c_int_content;
            }
            else {
                t_int_column_width =
                        t_tree_view->columnWidth(
                            cassandra::ns_gesn_column_number::c_int_content);
            }
 
            t_int_column_width -=
                    2 * cassandra::nsg_text_positioning::c_int_indentation;
 
            int t_int_width_space = option.fontMetrics.width(QChar(' '));
 
            if(!mv_map_position_word_width.contains(index)) {
                QStringList t_string_list_words =
                        index.data().toString().split(QRegExp("\\s+|-"));
 
                int t_int_words_count = t_string_list_words.size();
 
                QVector<int> t_vector_words_width(t_int_words_count);
                for (int i = 0; i < t_int_words_count; ++i) {
                    int t_int_current_word =
                            option.fontMetrics.width(t_string_list_words[i]);
                    t_vector_words_width.append(t_int_current_word);
                }
 
                mv_map_position_word_width[index] = t_vector_words_width;
            }
 
            const QVector<int>& t_vector_words_width =
                    mv_map_position_word_width[index];
 
            int t_int_words_count = t_vector_words_width.size();
            int t_int_current_string_width = 0;
            int t_int_string_count = 0;
            int t_int_words_count_in_string = 0;
 
            for (int i = 0; i < t_int_words_count; ++i) {
                if(t_vector_words_width.at(i) == 0) {
                    continue;
                }
 
                if(t_int_current_string_width + t_vector_words_width.at(i)
                        > t_int_column_width) {
 
                    if(t_int_words_count_in_string != 0) {
                        t_int_current_string_width =
                                t_vector_words_width.at(i) + t_int_width_space;
                        t_int_words_count_in_string = 1;
                    }
 
                    ++t_int_string_count;
                }
                else {
                    t_int_current_string_width +=
                            t_vector_words_width.at(i) + t_int_width_space;
 
                    ++t_int_words_count_in_string;
                }
            }
 
            int t_int_height =
                    (t_int_string_count + 1) * option.fontMetrics.height();
 
 
            if(t_int_height >= cassandra::ns_gesn_row_heigth::c_int_default) {
                t_size.setHeight(
                            t_int_height +
                            cassandra::nsg_text_positioning::c_int_indentation);
            }
            else {
                t_size.setHeight(cassandra::ns_gesn_row_heigth::c_int_default);
            }
        }
        else {
            t_size.setHeight(cassandra::ns_gesn_row_heigth::c_int_default);
        }
    } break;
    }
 
    return t_size;
}
/**
  ******************************************************************************
 
  ******************************************************************************
*/
void cassandra::oGesnDelegate::mf_remove_from_cash_type_work(
        const QModelIndex& index) {
    mv_map_position_type_work.remove(
                index.sibling(
                    index.row(),
                    cassandra::ns_gesn_column_number::c_int_rationale));
 
    QTreeView * t_tree_view = qobject_cast<QTreeView*>(parent());
    if(t_tree_view) {
        t_tree_view->dataChanged(
                    index,
                    index,
                    QVector<int>(1, Qt::SizeHintRole));
    }
}


Вернуться к обсуждению:
Перенос текста в ячейке C++ Qt
0
Заказать работу у эксперта
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
22.05.2020, 12:42
Готовые ответы и решения:

Перенос текста в ячейке
ребят, ячейка с переносом текста...в ячейке 3 строки....как скопировать только первую строку...

Перенос текста в ячейке DataGridView
Имеется форма на ней Кнопка и DataGridView , предположим в две колонки , жмем кнопку добавляется...

Перенос текста в ячейке EXCEL
Необходимо перенести текст в ячейке в определенном месте. (Аналог в екселе нажатие ALT + Enter). ...

Перенос текста в ячейке ListView
Здравствуйте. Скажите пожалуйста, если длина текста помещаемого в ячейку ListView больше длины...

3
22.05.2020, 12:42
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
22.05.2020, 12:42
Помогаю со студенческими работами здесь

Перенос текста в ячейке ListView
Всем привет! есть листвей со столбцом шириной 50. как сделать так, если текст не помещается в...

Перенос текста, если не хватает места в ячейке на другую ячейку
Ребят, выручайте, нужно сделать перенос текста в другую ячейку, если первая закончилась. Нашла...

Имя листа как дата в ячейке, либо замена части текста в ячейке
Друзья. Всю голову сломал. Никак не получается имя листа (а таких листов в рабочем документе у меня...

Выравнивание текста в ячейке грида при вводе текста
Вечер добрый. Не подскажите, у меня выравнивание работает (по вертикале и 5 пикселей от левого края...

Выравнивание текста в ячейке по вертикали в зависимости от высоты текста
Подскажите, есть ли возможность прорисовывать текст в ячейке грида, в зависимости от её высоты....

Копировать из строки текста в ячейке части текста и вставить
Проблема в том, что есть несколько файлов с отчетами (я их в приложенной книге указал на листах),...

0
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru