Nominate our 2022 Qt Champions!

[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);

    here my widget

    @ QWidget *widget1;
    widget1 = new QWidget;

    € 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.


  • bq. Your adventure with

    hahaha, that sounds sweet,

    I uploaded the whole project here,

    and here is a screenshot what it does

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


    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.


  • 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