Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProxyStyle & PE_IndicatorBranch Drawing logic
Forum Updated to NodeBB v4.3 + New Features

QProxyStyle & PE_IndicatorBranch Drawing logic

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 103 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by
    #1

    Hello

    I'm trying to understand how to draw my decorators... the line next to the item in QTreeView/etc

    handle all the cases of decorator that cab happen, item, multi item, child items, etc etc, say this >
    0daf74f6-7c30-462a-a6ac-2ea50ad69f12-image.png
    I want to for example, not draw circle on 1st decorator on left if there child on right and so on.
    Draw ending line, starting line, corner line for children, etc etc.

    I tried with
    const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(option);

    But the index is always invalid.
    How do I know which decorator I'm drawing, leftc/right/right/right etc etc if there multi child logic/etc /etc?

    Any guides/hints would be great!

    Regards
    Dariusz

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on last edited by
      #2

      Ok figured it out, its suprisingly simple...
      https://doc.qt.io/qt-6/style-reference.html#tree-branch-indicators

              int xMid = rect.center().x();
              int yMid = rect.center().y();
              int dotRadius = 4;
              QRect indicatorRect(xMid - 5, yMid - 5, 10, 10);
              const auto state = viewOpt->state;
              if (state & State_Children) {
                  painter->setPen(Qt::red);
                  painter->drawRect(indicatorRect);
                  if (state & State_Open) {
                      painter->setPen(Qt::blue);
                      painter->drawEllipse(QPoint(xMid, yMid), dotRadius, dotRadius);
                  } else {
                      painter->setPen(QColor(0, 0, 0));
                      painter->drawLine(0, yMid, rect.right(), yMid);
                  }
              }
              if (state & State_Item) {
                  painter->setPen(QColor(0, 150, 0));
                  painter->drawEllipse(QPoint(xMid, yMid), dotRadius / 2, dotRadius / 2);
                  if (state & State_Sibling) {
                      painter->drawLine(xMid, rect.top(), xMid, rect.bottom());
                  } else {
                      painter->drawLine(xMid, rect.top(), xMid, yMid);
                      painter->drawLine(xMid, yMid, rect.right(), yMid);
                  }
              } else {
                  painter->setPen(QPen(QColor(0, 150, 150), 4));
                  if (state & State_Sibling) {
                      painter->drawLine(xMid, rect.top(), xMid, rect.bottom());
                  }
              }
      

      687a69b6-0129-49b2-aa45-e9b8cbf6be3f-image.png

      1 Reply Last reply
      0
      • D Dariusz has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved