You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

matic

Beginner

  • "matic" is male
  • "matic" started this thread

Posts: 15

Location: italy

  • Send private message

1

Tuesday, September 9th 2008, 3:39pm

Using QPainter to draw custom graph [Solved]

Hallo all

I need to draw a graph (with nodes and edges) into a main window. To do this, I wrote a custom widget subclassing QLabel, and reimplementing the

Source code

1
void paintEvent(QPaintEvent*)
function. Everything goes fine, but I am unable to get the width and the height of the drawing area.
If I use the methods width() and height(), I get 100:30, even if I really don't understand where these values come from, since the size policy of my widget is set to Expanding, and it covers almost all the main window (when the window opens, the drawing area is almost 500x500, and it changes according to the resizing of the window).

Another question: is QLabel the right widget to subclass when I need to reimplement the paintEvent(), or there is some other widget more suitable ?

Thank you
Mtc

This post has been edited 1 times, last edit by "matic" (Sep 10th 2008, 4:08pm)


matic

Beginner

  • "matic" is male
  • "matic" started this thread

Posts: 15

Location: italy

  • Send private message

2

Wednesday, September 10th 2008, 4:07pm

RE: Using QPainter to draw custom graph

If I use the methods width() and height(), I get 100:30, even if I really don't understand where these values come from, since the size policy of my widget is set to Expanding, and it covers almost all the main window (when the window opens, the drawing area is almost 500x500, and it changes according to the resizing of the window).
Ok, I got it. width() and height() works correctly, probably I was asking the size of the object when it was not yet displayed