« Return to Thread: Tooltip on the table cell

Re: Tooltip on the table cell

by Massimo Petrillo :: Rate this Message:

Reply to Author | View in Thread


Hi,
I used this solution:
Subclass qx.ui.table.Table and put this lines in the constructor

        this.tooltip = new qx.ui.tooltip.ToolTip("");
        this.setToolTip(this.tooltip);
        this.addListener("mousemove", this.showTooltip, this);
        this.addListener("mouseout", function(e) {
            this.tooltip.hide();
        }, this);

add the method:
      showTooltip: function(e) {
          var v = null;
          var pageX = e.getDocumentLeft();
          var pageY = e.getDocumentTop();
          var sc = this.getTablePaneScrollerAtPageX(pageX);
          if (sc != null) {
              var tm = this.getTableModel();
              if (tm != null) {
                  var row = sc._getRowForPagePos(pageX, pageY);
                  var col = sc._getColumnForPageX(pageX); /**/
                  if (row >= 0 && col >= 0) {
                      try {
                          v = tm.getToolTip(col, row);
                      } catch (az) {
                          v = "";
                      }
                  }
              }
          }
          if (v != null & v != "") {
              this.tooltip.placeToMouse(e);
              this.tooltip.setLabel(v);
              this.tooltip.show();
          } else
              this.tooltip.hide();
      }

and make sure the table model you use has the method getToolTip. I also subclassed qx.ui.table.model.Simple with this version of getToolTip

      getToolTip: function(column, row) {
          if (column >= 0 && row >= 0) {
              try {
                  return this.getValue(column, row);
              } catch (e) {
                  return null;
              }
          }
      }

In this case the tooltip is simply the content of the cell.

I wonder if there is a better solution.

Regards
Massimo

 « Return to Thread: Tooltip on the table cell