Qt android paintevent problem?



  • #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::paintEvent(QPaintEvent *event)
    {
    QPainter painter(this);
    painter.setPen(QPen(Qt::red,4));
    painter.drawLine(QPoint(10,10),QPoint(100,400)); //drawLine() Without any effect, without any display?
    painter.setBrush(Qt::yellow);
    painter.drawRect(100,100,100,100);//drawRect() Without any effect, without any display?
    }

    //On the QT Android 6 system。
    //drawLine(),drawRect() Without any effect, without any display?
    //How to use painter()??



  • Usually, you are not supposed to draw on QMainWindow directly. You should only draw on elements placed on the window.

    Also, when you claim that a function call does not have any effect, check first that it gets executed - It may well be that your paintEvent doesn't get called, lacking a reason to update it... (there should be an update() call generated somewhere).


  • Moderators

    @kkkkxxxx
    as @mvuori said, don't draw on the main window directly. There is a placed widget over your paintings so you wont see them.
    What are you exactly trying to achieve?


Log in to reply
 

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