TPaveText position before drawing


If I create a TPaveText, and change its co-ordinates before drawing, the changes don’t apply…

TPaveText t(0.1,0.1,0.2,0.2,"NDC");
t.GetY1NDC(); <--- returns 0.05
t.Draw(); <---- draws box at 0.1,0.1,0.2,0.2
t.GetY1NDC(); <---- returns 0.1
t.Draw(); <----- now it draws correctly.

What do I need to do to be able to update the pave co-ordinates before the first draw!?


1 Like

SetY1NDC() is inherited from TPave and does not seems to be taken into account by TPaveTExt.
It looks ok with SetY1()

Hmm, that’s a nuisance. Is there a conversion method (perhaps in TPad?) that I can use to convert my calculated NDC co-ordinates to non NDC? Although seems a pain as after the first draw, using the NDC co-ordinates works ok.

Could I get it to force Draw (Paint?) and then Draw again? How could do I do this in some non-macro code? Having Draw called twice doesn’t do the trick, because simply calling the Draw method doesn’t seem to trigger enough activity to actually “draw” the pave on screen. Is there a Draw(), pad->Update(), Draw() combo I could use here or similar?



1 Like


I somehow need do disagree.
I use the current v5-34-00-patches branch.
Changing the coordinates via SetY1NDC works NEITHER before nor after any Draw (they remain the same as given in the TPaveText constructor call).
Changing the coordinates via SetY1 works well in any case (plus “gPad->Modified(); gPad->Update();” after the first Draw, no need to Draw it again, however).

Same for me. As I said this setters are inherited from un upper class but not used the le lower one (TPaveText).

They must be used at some point, because I definitely seem to be able to work with the SetxxNDC() methods once the object has been drawn to my canvas/pad, and then the subsequent Draws of the TPaveText (which occur in a method that refreshes and rebuilds my canvas for me) do seem to use these values correctly.

I’ll try to put together a minimal code example.

Here we go. Put the following in a file

TPaveText* pave = 0;
TH1D* h = new TH1D("h","",10,0,10);
TCanvas *c = 0;

void Redraw() {
   if(!c) {
      c = new TCanvas;
   if(!pave) {
      pave = new TPaveText(0.2,0.2,0.4,0.4,"NDC");




Then .L the file and call “Redraw()” - the first time you call it, the pave is in the bottom left corner. The second time you call it, it moves to the top right.
I want to make it be in the top right the first time it is called!