Skip to content

Commit

Permalink
qt_dotgraph: reduced label font size to fit inside bounding box of su…
Browse files Browse the repository at this point in the history
…rrounding shape
  • Loading branch information
DorianScholz authored and dirk-thomas committed Jan 23, 2017
1 parent e8af63a commit 769601d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions qt_dotgraph/src/qt_dotgraph/edge_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, highlight_level, spline, label_center, label, from_node, to_n
self._label = None
if label is not None:
self._label = QGraphicsSimpleTextItem(label)
self._label.setFont(GraphItem._LABEL_FONT)
label_rect = self._label.boundingRect()
label_rect.moveCenter(label_center)
self._label.setPos(label_rect.x(), label_rect.y())
Expand Down
6 changes: 5 additions & 1 deletion qt_dotgraph/src/qt_dotgraph/graph_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from python_qt_binding.QtGui import QColor
from python_qt_binding.QtGui import QColor, QFont
from python_qt_binding.QtWidgets import QGraphicsItemGroup


Expand All @@ -41,6 +41,10 @@ class GraphItem(QGraphicsItemGroup):
_COLOR_RED = QColor(255, 0, 0)
_COLOR_TEAL = QColor(0, 170, 170)

_LABEL_FONT = QFont('sans', weight=QFont.Light)

def __init__(self, highlight_level, parent=None):
super(GraphItem, self).__init__(parent)
self._highlight_level = highlight_level
# use device depended font size to produce
GraphItem._LABEL_FONT.setPixelSize(11)
1 change: 1 addition & 0 deletions qt_dotgraph/src/qt_dotgraph/node_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(self, highlight_level, bounding_box, label, shape, color=None, pare
self.addToGroup(self._graphics_item)

self._label = QGraphicsSimpleTextItem(label)
self._label.setFont(GraphItem._LABEL_FONT)
label_rect = self._label.boundingRect()
if label_pos is None:
label_rect.moveCenter(bounding_box.center())
Expand Down
2 changes: 2 additions & 0 deletions qt_dotgraph/src/qt_dotgraph/pydotfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def add_node_to_graph(self,
node.set_label(self.escape_label(nodelabel))
if tooltip is not None:
node.set_tooltip(tooltip)
elif url is not None:
node.set_tooltip(url)
if url is not None:
node.set_URL(self.escape_name(url))
if color is not None:
Expand Down

0 comments on commit 769601d

Please sign in to comment.