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
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
Frame m;
m.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
Frame m;
m.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#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:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
Q_OBJECT
public:
}
protected:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QtGui>
#include<QtCore>
#include<QtDebug>
#include<QFrame>
namespace Ui {
class MainWindow;
class Frame;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
class Frame : public QFrame{
Q_OBJECT
public:
Frame( QWidget * parent = NULL ) : QFrame(parent){
}
protected:
void paintEvent( QPaintEvent * event );
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
{
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(25);
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.
setRenderHint(QPainter::SmoothPixmapTransform,
true);
painter.setPen(linepen);
painter.drawLine(100,100,300,300);
}
#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 Frame::paintEvent( QPaintEvent * event )
{
QFrame::paintEvent(event);
QPainter painter(this);
QPen linepen(Qt::red);
linepen.setCapStyle(Qt::RoundCap);
linepen.setWidth(25);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.setRenderHint(QPainter::SmoothPixmapTransform,true);
painter.setPen(linepen);
painter.drawLine(100,100,300,300);
}
To copy to clipboard, switch view to plain text mode
Bookmarks