#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"QWidget"
#include <QtGui>
#include "QPixmap"
#include"QPen"
#include<iostream>
using namespace std;
{
public:
MyWidget();
protected:
};
MyWidget::MyWidget()
{
}
{
QRectF rectangle
(50,
50,
300,
300);
painter.
setRenderHint(QPainter::Antialiasing);
QPen pen
(Qt
::green,
30, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin);
int input=75;
int level=input/20;
int rem=input-level*20;
float a;
switch(level)
{
case 0:
pen.
setColor(QColor(0,
255,
0,
255));
painter.setPen(pen);
a=.1*rem;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 1:
pen.
setColor(QColor(rem
*6,
255,
0,
255));
painter.setPen(pen);
a=.4;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 2:
pen.
setColor(QColor(127+rem
*6,
255,
0,
255));
painter.setPen(pen);
a=.6;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 3:
pen.
setColor(QColor(255,
255-rem
*6,
0,
255));
painter.setPen(pen);
a=.8;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 4:
pen.
setColor(QColor(255,
127-rem
*6,
0,
255));
painter.setPen(pen);
a=.8;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
default:
pen.
setColor(QColor(255,
0,
0,
255));
painter.setPen(pen);
a=1;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
}
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
//setStyleSheet("MainWindow {background-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg');background-repeat: repeat;background-position: top right;}");
setStyleSheet("MainWindow {border-width: 4px; border-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg') 4 4 4 4 stretch stretch;}");
MyWidget* my_widget = new MyWidget();
QWidget::setFixedSize ( 400,
400 );
setCentralWidget(my_widget);
setWindowTitle
(QApplication::translate("toplevel",
"Main widget"));
}
MainWindow::~MainWindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"QWidget"
#include <QtGui>
#include "QPixmap"
#include"QPen"
#include<iostream>
using namespace std;
class MyWidget : public QWidget
{
public:
MyWidget();
protected:
void paintEvent(QPaintEvent *);
};
MyWidget::MyWidget()
{
}
void MyWidget::paintEvent(QPaintEvent *event)
{
QRectF rectangle(50,50,300,300);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPen pen(Qt::green, 30, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
int input=75;
int level=input/20;
int rem=input-level*20;
float a;
switch(level)
{
case 0:
pen.setColor(QColor(0,255,0,255));
painter.setPen(pen);
a=.1*rem;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 1:
pen.setColor(QColor(rem*6,255,0,255));
painter.setPen(pen);
a=.4;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 2:
pen.setColor(QColor(127+rem*6,255,0,255));
painter.setPen(pen);
a=.6;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 3:
pen.setColor(QColor(255,255-rem*6,0,255));
painter.setPen(pen);
a=.8;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
case 4:
pen.setColor(QColor(255,127-rem*6,0,255));
painter.setPen(pen);
a=.8;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
default:
pen.setColor(QColor(255,0,0,255));
painter.setPen(pen);
a=1;
painter.setOpacity(a);
painter.drawRect(50, 50, 300, 300);
break;
}
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//setStyleSheet("MainWindow {background-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg');background-repeat: repeat;background-position: top right;}");
setStyleSheet("MainWindow {border-width: 4px; border-image:url('/Users/sandeep_hyd123/Qt sandy/first/photo.jpeg') 4 4 4 4 stretch stretch;}");
MyWidget* my_widget = new MyWidget();
QWidget::setFixedSize ( 400, 400 );
setCentralWidget(my_widget);
setWindowTitle(QApplication::translate("toplevel", "Main widget"));
}
MainWindow::~MainWindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks