Hi All
I already promoted my QLabel, and my purpose is to draw a Line on QLabel a line when I click a button but some thing wrong here I couldn't find any thing.I add my codes here . Thank you very much.
mylabel.h
#ifndef MYLABEL_H
#define MYLABEL_H
#include <QLabel>
{ Q_OBJECT
public:
protected:
};
#endif
#ifndef MYLABEL_H
#define MYLABEL_H
#include <QLabel>
class myLabel :public QLabel
{ Q_OBJECT
public:
myLabel(QWidget *parent);
protected:
void paintEvent(QPaintEvent *pe);
};
#endif
To copy to clipboard, switch view to plain text mode
mylabel.cpp
#include <QPainter>
#include "myLabel.h"
{}
{
painter.setPen( Qt::blue );
painter.drawLine(0,0,400,320);
}
#include <QPainter>
#include "myLabel.h"
myLabel::myLabel (QWidget *parent)
: QLabel(parent)
{}
void myLabel::paintEvent(QPaintEvent *pe)
{
QPainter painter(this);
painter.setPen( Qt::blue );
painter.drawLine(0,0,400,320);
}
To copy to clipboard, switch view to plain text mode
deneme.cpp
#include "deneme.h"
#include "myLabel.h"
{
ui.setupUi(this);
connect(ui.pushButton,SIGNAL(clicked()),ui.label,SLOT(drw()));
}
deneme::~deneme()
{
}
void deneme::drw()
{
ui.label->update();
}
#include "deneme.h"
#include "myLabel.h"
deneme::deneme(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.pushButton,SIGNAL(clicked()),ui.label,SLOT(drw()));
}
deneme::~deneme()
{
}
void deneme::drw()
{
ui.label->update();
}
To copy to clipboard, switch view to plain text mode
deneme.h
#ifndef DENEME_H
#define DENEME_H
#include <QtGui/QMainWindow>
#include "ui_deneme.h"
{
Q_OBJECT
public:
~deneme();
private:
Ui::denemeClass ui;
protected:
void drw();
};
#endif // DENEME_H
#ifndef DENEME_H
#define DENEME_H
#include <QtGui/QMainWindow>
#include "ui_deneme.h"
class deneme : public QMainWindow
{
Q_OBJECT
public:
deneme(QWidget *parent = 0);
~deneme();
private:
Ui::denemeClass ui;
protected:
void drw();
};
#endif // DENEME_H
To copy to clipboard, switch view to plain text mode
somepart of ui_deneme.h
#ifndef UI_DENEME_H
#define UI_DENEME_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>
#include "mylabel.h"
class Ui_denemeClass
{
public:
myLabel *label;
{
if (denemeClass->objectName().isEmpty())
denemeClass
->setObjectName
(QString::fromUtf8("denemeClass"));
denemeClass->resize(800, 480);
denemeClass
->setMinimumSize
(QSize(800,
480));
denemeClass
->setMaximumSize
(QSize(800,
480));
centralwidget
= new QWidget(denemeClass
);
centralwidget
->setObjectName
(QString::fromUtf8("centralwidget"));
pushButton
->setObjectName
(QString::fromUtf8("pushButton"));
pushButton
->setGeometry
(QRect(70,
140,
75,
24));
label = new myLabel(centralwidget);
label
->setObjectName
(QString::fromUtf8("label"));
label
->setGeometry
(QRect(150,
0,
471,
341));
denemeClass->setCentralWidget(centralwidget);
statusbar
->setObjectName
(QString::fromUtf8("statusbar"));
denemeClass->setStatusBar(statusbar);
#ifndef UI_DENEME_H
#define UI_DENEME_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QStatusBar>
#include <QtGui/QWidget>
#include "mylabel.h"
class Ui_denemeClass
{
public:
QWidget *centralwidget;
QPushButton *pushButton;
myLabel *label;
QStatusBar *statusbar;
void setupUi(QMainWindow *denemeClass)
{
if (denemeClass->objectName().isEmpty())
denemeClass->setObjectName(QString::fromUtf8("denemeClass"));
denemeClass->resize(800, 480);
denemeClass->setMinimumSize(QSize(800, 480));
denemeClass->setMaximumSize(QSize(800, 480));
centralwidget = new QWidget(denemeClass);
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
pushButton = new QPushButton(centralwidget);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(70, 140, 75, 24));
label = new myLabel(centralwidget);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(150, 0, 471, 341));
denemeClass->setCentralWidget(centralwidget);
statusbar = new QStatusBar(denemeClass);
statusbar->setObjectName(QString::fromUtf8("statusbar"));
denemeClass->setStatusBar(statusbar);
To copy to clipboard, switch view to plain text mode
Bookmarks