Get TPad from TCanvas

Hello,

I created TCanvas and then several TPad. Then I drew them. If I understand I can get TVirtualPad from TCanvas using TCanvas::cd(). After doing it I called GetName(), but instead of name of TPad i see the name of canva.
So, how i can get real TPad from TCanvas?

P.S.: Actually, i want to SetLogy() and SetLogx() in a pad, but I want to get this pad from a canva.

Best regards,
Nazar

Can you post a small macro reproducing your problem ?

void foo(TCanvas *);

int main()
{
TCanvas *c;
TPad *p1, *p2;

 c = new TCanvas("c_name", "c_title", 800, 900);
 p1 = new TPad("p1", "p1", ....);
 p2 = new TPad("p2", "p2", ....);
 p1->Draw();
 p2->Draw();
 foo(c);
 return (0);

}

void foo(TCanvas *aCanva)
{
TVirtualPad *p1;

 p1 = aCanva->cd(0);
 printf("pad name: %s\n", p1->GetName());
 p1->SetLogx();
 return;

}

But GetName return the name of a canva and Logx() in p1 isn’t setted.

Well, “cd(0)” means the main pad (i.e., the canvas itself).
You need “cd(1)” (the first subpad) and “cd(2)” (the second subpad).

BTW. A dedicated variable “gPad” exists and is a pointer to the “current (sub)pad”.

Thanks, but cd(1) and cd(2) still return the name of a canva, but not the pad.
Is it a bug or I don’t understand something?

Well, it looks like you need (because you create pads manually):
p1 = new TPad("p1", "p1", ....); p1->SetNumber(1);
p2 = new TPad("p2", "p2", ....); p2->SetNumber(2);

Yes! Thanks, it works!
Now I see that there is fNumber that is pad number identifier, but I didn’t know that pads aren’t numerated when i draw them on a canva.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.