<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904505</guid>
        <pubDate>Tue, 21 May 2024 10:37:05 +0000</pubDate>
        <title>QHeaderView: как убрать нумерацию строк в вертикальном заголовке таблицы?</title>
        <link>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904505</link>
        <description><![CDATA[vlad2: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=445794&view=findpost&p=3904502'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Majestio &#064; <time class="tag-quote__quoted-time" datetime="2024-05-21T12:54:57+03:00">21.05.24, 09:54</time></span><div class='quote '>Работу с моделями и делегатами я тебе показывал</div></div>Спасибо, буду смотреть.]]></description>
        <author>vlad2</author>
        <category>Кроссплатформенный C/C++: cl/gcc/Qt/Gtk+/WxWidgets</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904502</guid>
        <pubDate>Tue, 21 May 2024 09:54:57 +0000</pubDate>
        <title>QHeaderView: как убрать нумерацию строк в вертикальном заголовке таблицы?</title>
        <link>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904502</link>
        <description><![CDATA[Majestio: Ну, ручная отрисовка - это самое последнее дело, что нужно использовать. Т.к. теряется &quot;стильность&quot; при создании кросс-платформенных приложений. Пользователь ожидает оформление выбранной им темы, а ему &quot;рисуют&quot;. Иными словами, когда вообще край - только тогда рисуй самостоятельно. Допустим, вывод изображения в ячейке потребует рисования, во всех остальных случаях лучше обойтись другими способами.<br>
<br>
Ну и по твоему вопросу этой темы ...<br>
<br>
<strong class='tag-b'>1) Ты можешь вообще спрятать вертикальный заголовок:</strong><br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">tableView-&#62;setVerticalHeaderVisible(false);</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<strong class='tag-b'>2) Ты можешь выводить произвольный текст, но откуда ты его возьмешь?</strong> <br>
<br>
Правильно - из твоей модели&#33; Ведь там, и только там находятся (или вычисляются на-лету) данные для отображения. Поэтому дополни/скорректируй поведение своей модели. Например:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;QAbstractTableModel&#62;</div><div class="code_line">#include &#60;QVariant&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">class MyModel : public QAbstractTableModel {</div><div class="code_line">&nbsp;&nbsp;public:</div><div class="code_line">&nbsp;&nbsp; &nbsp;int rowCount(const QModelIndex &amp;parent = QModelIndex()) const override {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Q_UNUSED(parent)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 0; // Замени на количество строк в твоей модели данных</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;int columnCount(const QModelIndex &amp;parent = QModelIndex()) const override {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Q_UNUSED(parent)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 1; // Замени на количество столбцов в твоей модели данных</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (orientation == Qt::Vertical &amp;&amp; role == Qt::DisplayRole) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Получаем данные из твоей модели данных</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Здесь предполагается, что у тебя есть метод data() для получения данных</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Замени на соответствующий код для твоей модели данных</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;QVariant data = data(index(section, 0), Qt::DisplayRole);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Тут синтетический пример вычисления текста ячейки вертикального заголовка на основе данных</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;QString text = (data.toInt() &#62; 0) ? &quot;+&quot; : &quot;-&quot;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return text;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return QAbstractTableModel::headerData(section, orientation, role);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;QVariant data(const QModelIndex &amp;index, int role = Qt::DisplayRole) const override {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Q_UNUSED(index)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Q_UNUSED(role)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;// Замени на соответствующий код для твоей модели данных</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return QVariant();</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">};</div></ol></div></div></div></div><br>
В приведенном примере в ячейках вертикального заголовка будет выводится минус или плюс в зависимости от данных, хранимых в твоей модели (где-то как-то это уже второй вопрос)<br>
<br>
<strong class='tag-b'>3) Чтобы вместо текста рисовать картинку нужен немного другой подход - модификацию делегата</strong>, например:<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">void MyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &amp;option, const QModelIndex &amp;index) const {</div><div class="code_line">&nbsp;&nbsp;if (index.column() == 0 &amp;&amp; index.row() &#60; model-&#62;rowCount()) {</div><div class="code_line">&nbsp;&nbsp; &nbsp;QString text = model-&#62;data(index, Qt::DisplayRole).toString();</div><div class="code_line">&nbsp;&nbsp; &nbsp;painter-&#62;drawText(option.rect, text); // тут &quot;рисуется&quot; текст, но можно рисовать и картинку</div><div class="code_line">&nbsp;&nbsp;} else {</div><div class="code_line">&nbsp;&nbsp; &nbsp;QStyledItemDelegate::paint(painter, option, index);</div><div class="code_line">&nbsp;&nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
Работу с моделями и делегатами я тебе показывал в моем тестовом проекте, который я тебе оставлял.<br>
<br>
<strong class='tag-b'><span class="tag-color tag-color-named" data-value="red" style="color: red">Ну и небольшое замечание:</span></strong> сорян, приведенные куски кода я не проверял - просто спросил у ChatGPT. Его ответы меня устроили, т.к. я помню, что такое делал когда-то сам. Ну а сидеть тестить и экспериментировать желания нет. Считаю, что самое главное - это показать куда &quot;правильно копать&quot; :)]]></description>
        <author>Majestio</author>
        <category>Кроссплатформенный C/C++: cl/gcc/Qt/Gtk+/WxWidgets</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904471</guid>
        <pubDate>Tue, 21 May 2024 07:01:03 +0000</pubDate>
        <title>QHeaderView: как убрать нумерацию строк в вертикальном заголовке таблицы?</title>
        <link>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904471</link>
        <description><![CDATA[vlad2: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=445794&view=findpost&p=3904459'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Majestio &#064; <time class="tag-quote__quoted-time" datetime="2024-05-21T06:01:36+00:00">21.05.24, 06:01</time></span><div class='quote '>присоедини свой пример</div></div>Да тот же самый, в <a class='tag-url' href='https://forum.sources.ru/index.php?showtopic=445302&st=0' target='_blank'>этой</a> ветке.<br>
Это вопрос на знание: если есть 2-3 функции, которые мне неизвестны, это одно, а если десятки строк кода, то проще отрисовать всю ячейку самому. Смысл в том, что ячейка вертикального заголовка должна быть пустой, либо с картинкой. Поэтому думал при помощи какой-то функции убрать текст или задать его пустым, а потом  нарисовать или нет на этом месте картинку. Без полной ручной отрисовки. Только и всего.]]></description>
        <author>vlad2</author>
        <category>Кроссплатформенный C/C++: cl/gcc/Qt/Gtk+/WxWidgets</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904459</guid>
        <pubDate>Tue, 21 May 2024 06:01:36 +0000</pubDate>
        <title>QHeaderView: как убрать нумерацию строк в вертикальном заголовке таблицы?</title>
        <link>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904459</link>
        <description><![CDATA[Majestio: <strong class='tag-b'>vlad2</strong>, присоедини свой пример ;)]]></description>
        <author>Majestio</author>
        <category>Кроссплатформенный C/C++: cl/gcc/Qt/Gtk+/WxWidgets</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904434</guid>
        <pubDate>Mon, 20 May 2024 09:21:03 +0000</pubDate>
        <title>QHeaderView: как убрать нумерацию строк в вертикальном заголовке таблицы?</title>
        <link>https://forum.sources.ru/index.php?showtopic=445794&amp;view=findpost&amp;p=3904434</link>
        <description><![CDATA[vlad2: Точнее: можно ли убрать текст (нумерацию строк) в вертикальном заголовке таблицы без полной ручной перерисовки ячейки в переопределённой функции paintSection класса QHeaderView?<br>Спасибо.]]></description>
        <author>vlad2</author>
        <category>Кроссплатформенный C/C++: cl/gcc/Qt/Gtk+/WxWidgets</category>
      </item>
	
      </channel>
      </rss>
	