實現對qpushbutton 刪除,新建,雙擊

2021-10-01 22:49:27 字數 2324 閱讀 9244

***功能描述:有個模板button。 a:對其單擊左鍵移動能新建乙個button(任意位置) b:對新建的物件也可以任意移動,單擊物件右鍵能刪除物件 c: 本打算雙擊可以編輯文字(發現有點難實現,就沒有繼續完善了)

a:重寫滑鼠事件類 (.h)

#ifndef mybutton_h

#define mybutton_h

#include

#include

#pragma execution_character_set("utf-8")

//utf-8編碼

#include

class

mybutton

:public qpushbutton

;#endif

// mybutton_h

b:重寫滑鼠類事件(.cpp)

#include

"mybutton.h"

#include

"qdebug.h"

#include

"ui_mainwindow.h"

mybutton::

mybutton

(qwidget *parent)

:qpushbutton

(parent)

void mybutton::

mousemoveevent

(qmouseevent *e)

}void mybutton::

mousepressevent

(qmouseevent *e)

}void mybutton::

mousereleaseevent

(qmouseevent *e)

c:mainwindow .h程式

public

:explicit

mainwindow

(qwidget *parent =

nullptr);

~mainwindow()

;

cbutton *lab;

//物件

bool flag=

true

;//新建標誌位

public

: ui::mainwindow *ui;

public slots:

void

labxy

(qpoint)

;//移動位置

voidok(

);//確認新建的button

void

deldel()

;//刪除控制項

void

textchange()

;//改變文字

d: mainwindow .cpp程式

#include

"mainwindow.h"

#include

"ui_mainwindow.h"

#include

"qdebug.h"

mainwindow::

mainwindow

(qwidget *parent)

:qmainwindow

(parent),ui

(new ui::mainwindow)

mainwindow::

~mainwindow()

void mainwindow::

labxy

(qpoint p)

lab-

>

move

(p);

//移動位置

}void mainwindow::ok(

)void mainwindow::

deldel()

void mainwindow::

textchange()

重寫第二個滑鼠繼承事件類,大同小異

主要看 cpp**

void cbutton::

mousemoveevent

(qmouseevent *e)

}void cbutton::

mousepressevent

(qmouseevent *e)

if(e-

>

button()

==qt::rightbutton)

}void cbutton::

mousedoubleclickevent

(qmouseevent *event)

//雙擊事件

pandas中對DateFrame進行刪除操作

import pandas as pd import numpy as np 建立dataframe資料 data1 pd.dataframe np.arange 12 reshape 4 3 columns a b c print data1 axis 1表示刪除一列 data2 data1.dr...

順序表的實現(頭插,頭刪尾插,尾刪)

順序表 順序表是在計算機記憶體中以陣列的形式儲存的線性表,是指用一組位址連續的儲存單元依次儲存資料元素的線性結構。線性表採用順序儲存的方式儲存就稱之為順序表。順序表是將表中的結點依次存放在計算機記憶體中一組位址連續的儲存單元中。順序表特點 將表中元素乙個接乙個的存入一組連續的儲存單元中,這種儲存結構...

jquery核取方塊checkbox實現刪除

實現這樣乙個基本需求,頁面有很多資料,可以刪除一條或多條,刪除前判斷是否選中至少一條,否則提示。function deleteuser if flag 將要集體刪除的資料 傳遞給action處理 window.self.location deleteuser?info array else 後台ac...