529 |
529 |
530 # step 2: find the index of the item to align in relation to |
530 # step 2: find the index of the item to align in relation to |
531 amount = None |
531 amount = None |
532 for i, item in enumerate(items): |
532 for i, item in enumerate(items): |
533 rect = item.sceneBoundingRect() |
533 rect = item.sceneBoundingRect() |
534 if ( |
534 if alignment == Qt.AlignmentFlag.AlignLeft and ( |
535 alignment == Qt.AlignmentFlag.AlignLeft |
535 amount is None or rect.x() < amount |
536 and (amount is None or rect.x() < amount) |
|
537 ): |
536 ): |
538 amount = rect.x() |
537 amount = rect.x() |
539 index = i |
538 index = i |
540 elif ( |
539 elif alignment == Qt.AlignmentFlag.AlignRight and ( |
541 alignment == Qt.AlignmentFlag.AlignRight |
540 amount is None or rect.x() + rect.width() > amount |
542 and (amount is None or rect.x() + rect.width() > amount) |
|
543 ): |
541 ): |
544 amount = rect.x() + rect.width() |
542 amount = rect.x() + rect.width() |
545 index = i |
543 index = i |
546 elif ( |
544 elif alignment == Qt.AlignmentFlag.AlignHCenter and ( |
547 alignment == Qt.AlignmentFlag.AlignHCenter |
545 amount is None or rect.width() > amount |
548 and (amount is None or rect.width() > amount) |
|
549 ): |
546 ): |
550 amount = rect.width() |
547 amount = rect.width() |
551 index = i |
548 index = i |
552 elif ( |
549 elif alignment == Qt.AlignmentFlag.AlignTop and ( |
553 alignment == Qt.AlignmentFlag.AlignTop |
550 amount is None or rect.y() < amount |
554 and (amount is None or rect.y() < amount) |
|
555 ): |
551 ): |
556 amount = rect.y() |
552 amount = rect.y() |
557 index = i |
553 index = i |
558 elif ( |
554 elif alignment == Qt.AlignmentFlag.AlignBottom and ( |
559 alignment == Qt.AlignmentFlag.AlignBottom |
555 amount is None or rect.y() + rect.height() > amount |
560 and (amount is None or rect.y() + rect.height() > amount) |
|
561 ): |
556 ): |
562 amount = rect.y() + rect.height() |
557 amount = rect.y() + rect.height() |
563 index = i |
558 index = i |
564 elif ( |
559 elif alignment == Qt.AlignmentFlag.AlignVCenter and ( |
565 alignment == Qt.AlignmentFlag.AlignVCenter |
560 amount is None or rect.height() > amount |
566 and (amount is None or rect.height() > amount) |
|
567 ): |
561 ): |
568 amount = rect.height() |
562 amount = rect.height() |
569 index = i |
563 index = i |
570 rect = items[index].sceneBoundingRect() |
564 rect = items[index].sceneBoundingRect() |
571 |
565 |