qtデスクトップ弾幕を実現
11616 ワード
初心者は初めて何かを書きます.
ノートにしてみよう
Qtは1つのプラットフォームC++グラフィックユーザーインタフェースアプリケーションの開発フレームワークにまたがって、アプリケーションソフトウェアのグラフィックはqtを持ってくるのが効率的で、今日デスクトップの弾幕を実現します
まず1つの弾幕類を完成して、共にQLabelに継承します
ノートにしてみよう
Qtは1つのプラットフォームC++グラフィックユーザーインタフェースアプリケーションの開発フレームワークにまたがって、アプリケーションソフトウェアのグラフィックはqtを持ってくるのが効率的で、今日デスクトップの弾幕を実現します
まず1つの弾幕類を完成して、共にQLabelに継承します
class barrage : public QLabel
{
Q_OBJECT
public:
explicit barrage(QString str, QWidget *parent = 0);
private:
QPropertyAnimation *animation;//
~barrage();
int duration;//
int pix;//
};
弾幕の構造関数の中で弾幕のルートに対して.移動時間、フォントサイズの初期化barrage::barrage(QString str, QWidget *parent):
QLabel(parent)
{
int hlevel;
int height=20;
int width=str.size()*height;
int desktop_high = QApplication::desktop()->height();
hlevel=desktop_high/10*(qrand()%10);
this->setText(str);
this->setAlignment(Qt::AlignCenter);//
this->resize(width,height);
animation=new QPropertyAnimation(this,"geometry",this);
animation->setDuration(10000);
animation->setKeyValueAt(0, QRect(1920,hlevel , width, height));
animation->setKeyValueAt(1, QRect(0-width, hlevel, width, height));
animation->start();
QFont font;
font.setPixelSize(height);
this->setFont(font);
}
接着写了一个MainScreen类 继承与QMainWindow作为主窗口,里面放了1000个弹幕类,
class MainScreen : public QMainWindow
{
Q_OBJECT
public:
explicit MainScreen(QWidget *parent = 0);
private:
barrage *barage[1000];
QPushButton *button;
QLineEdit *edit;
int barnum;//
signals:
public slots:
void SendBar();//
};
コンストラクション関数で背景を透明にします//
setAutoFillBackground(false); //
setWindowFlags(Qt::FramelessWindowHint);
ボタンと編集ボックスの通過setAttribute(Qt::WA_TranslucentBackground,true);
setGeometry(int,int,int,int)サイズと位置を設定する//
int desktop_width = QApplication::desktop()->width();
int desktop_high = QApplication::desktop()->height();
this->resize (desktop_width, desktop_high);
button =new QPushButton(" ",this);
button->setGeometry(800,800,100,20);
edit=new QLineEdit(this);
edit->setGeometry(920,800,100,20);
( barrage)