PDA

View Full Version : paint central widget of a QMainWindow???



Shuchi Agrawal
12th January 2007, 11:10
Below are the codes. so can any1 check them n tel tht is it the right way to paint(draw line n a point) on the central widget on a menu click event?[i think its not the right way, though its working]

824

825

826

wysota
12th January 2007, 12:23
You should set an external central widget and paint on that widget and not on the main window itself.

By the way, how is this question related to Qt Designer?

Shuchi Agrawal
17th January 2007, 07:30
You should set an external central widget and paint on that widget and not on the main window itself.

so for this do i need QStackedWidget ? or simply a obj. of QWidget n set it as central widget???


By the way, how is this question related to Qt Designer?

sorry!! fm next time i wil take care..

jpn
17th January 2007, 08:02
so for this do i need QStackedWidget ? or simply a obj. of QWidget n set it as central widget???
The central widget can be anything inheriting from QWidget, but I think Qt Designer restricts it to be a QWidget. Just create any custom widget, reimplement the paintEvent(), add corresponding widget in the Designer and promote it (http://doc.trolltech.com/4.2/designer-using-custom-widgets.html#promoting-widgets).

As I have said previously:

Override QWidget::paintEvent() for the widget you want to paint on and use QPainter to draw the line. For example, if you want to paint on the central widget in a main window, you must reimplement the paintEvent() for the central widget, not for the main window.
So, in another words.
WRONG: "void MyMainWindow::paintEvent(QPaintEvent* event)"
CORRECT: "void MyCentralWidget::paintEvent(QPaintEvent* event)"