[SOLVED] Inserting Paintevent into own Widget



  • Hey, this driving me crazy,

    how can I insert a paint event into a custom widget

    if this is my mini paintevent

    @void Lines::paintEvent(QPaintEvent *e)
    {

    QPainter qp(this);
    QPen pen (Qt::blue, 2, Qt::SolidLine);
    qp.setPen(pen);
    qp.drawRect(100,100,100,100);}@

    here my widget

    @ QWidget *widget1;
    widget1 = new QWidget;
    widget1->show();@

    € or maybe you could tell me, how to insert buttons/labels into a paintevent window.
    this would also work for my problem.



  • Can we see the rest of Your code?. And can You can explain what exactly do You want to achieve?

    In my opinion You should read some Qt tutorial/examples before starting Your adventure with Qt.

    poor_Robert



  • bq. Your adventure with Qt.bq.

    hahaha, that sounds sweet,

    I uploaded the whole project here,
    http://www.mediafire.com/?gubgnqk6281j8l8

    and here is a screenshot what it does
    http://img690.imageshack.us/img690/6371/89805244.jpg

    it draws a sinus with dots, after finishing it restarts the sinus curve,
    and line connects the new and old sinus

    O.O

    I need now some buttons, labels, slots to control/change the curve.
    But I want the buttons to be in the same widget/window as the curve



  • Hmmm,

    If I were You I would just add some QChecBoxes, QSpinBoxes and other Qt's stock widgets. I would place those sub-widgets to the same layout as Your plot, then I would connect their signals to my plot's slots to do desired things.

    But, if You want to have Your own buttons, labels, etc maybe You should think about createing Your own "Plot control widgets". In such case You should derive from QWidget and override methods like mousePressEvent, paintEvent etc to achieve what You want.

    poor_Robert



  • No, it can be done so much easier,
    all you have to do is to create a MainWindow,
    the paintevent is automatically drawn inside it,
    and wherever you put your buttons and labels, they will be there.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.