I have created a ui window(mainwindow.ui). then i have added 3 qframe(Frame1, Frame2,Frame3) on the ui. then i placed an background image on the frame2.
Then i have created a class frame on the mainwindow.h. I have created a paintEvent of Qframe on the header in frame class. My purpose is to create a Qframe on the class frame. Then place that frame into the frame2 of the mainwindow.ui. So that i can draw over the background image of frame2. i don want painting in the frame1 & frame3. I frame2 i have to draw over the background image.
I coded and when i run my project the mainwindow.ui & frame class will run in 2different window.
main.cpp
Code:
#include <QtGui/QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { MainWindow w; w.show(); Frame m; m.show(); return a.exec(); }
mainwindow.h
Code:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include<QtGui> #include<QtCore> #include<QtDebug> #include<QFrame> namespace Ui { class MainWindow; class Frame; } { Q_OBJECT public: ~MainWindow(); private: Ui::MainWindow *ui; }; Q_OBJECT public: } protected: }; #endif // MAINWINDOW_H
mainwindow.cpp
Code:
#include "mainwindow.h" #include "ui_mainwindow.h" ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } { linepen.setCapStyle(Qt::RoundCap); linepen.setWidth(25); painter.setPen(linepen); painter.drawLine(100,100,300,300); }