QCommandLinkButton شرح ال

 QCommandLinkButton 

1-Create object of QPushButton:

btn = QPushButton("name")

Btn.setObjectName(‘coded_name’) #أسم الزرار في الكود

Btn.move(x,y)تحرك الزرار#   

Btn.resize(width,height)  # تغير عرض وأرتفاع الزرار

btn.setToolTip)'This is a simple button') تظهر ملحوظة علي الزرار#

btn.setVisible() #True تخفي الزرار اذا أخذت 

 

2-Properties and Functions:

Btn.text():text

ترجع النص المكتوب علي الزرار

Btn.setText(“النص”)::string

تضع النص علي الزرار

btn.setIcon(QIcon("pic.exten"))

تضع أيقونة علي الزرار

Btn.isChecked():True,False

تستخدم لاختبار هل الزرار مضعوط بأسمرار ام لا

اذا كان الزر مضغوط مفعل للضغط بأستمرارtrueترجع 

Btn.setCheckable()::True,False

 لجعل الزرار مضغوط باستمرارtrueتأخذ

btn.setEnabled(False)::True,False

 لجعل الزرار غير مفعل و العكسFalseتأخذ

btn.hide()

تخفي الزرار عند تنفيذها

btn.setFlat()::True,False

True أخدت تجعل الزر بدون حواف أذا

وعند الضغظ عليه تظهر الحواف

btn.description()

ترجع الوصف الموجود علي الزرار تحت الأسم

تضيف وصف علي الزرار يظهر أسفل أسم الزرار:                                

btn.setDescription('bmjhdjahdajsdhajs,dhasdjh')

self.menu = QMenu()             #create menu
self.menu.addAction("osama")    #add action1 in menu
self.menu.addAction("osama1")   #add action2 in menu
btn.setMenu(self.menu)          #add menu to button

تحدد شكل الماوس عند الوقوف علي الزرار:                                         

from PyQt5.QtCore import Qt

button.setCursor(QCursor(Qt.PointingHandCursor))

 

3-Signals:

btn.clicked.connect(slot_fun)

تنفذ الحدث عند الضغط علي الزرار

btn.pressed.connect(slot_fun)

تنفذ الحدث طول ما الزرارمضغوط عليه

btn.released.connect(slot_fun)

تنفذ الحدث عند ترك الزرار بعد الضغط

Ex:

class Window(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Python ")
        self.setGeometry(100, 100, 500, 400)
        self.count = 0
        self.UiComponents()
    def UiComponents(self):
        cl_button = QCommandLinkButton("Press", self)
        cl_button.clicked.connect(self.label_text)
        # cl_button.setGeometry(200, 100, 150, 60)
        # a = QAction("Next Geeks", self)
        # b = QAction("Previous Geeks", self)
        # menu = QMenu()
        # menu.addActions([a, b])
        # cl_button.setMenu(menu)
        # cl_button.showMenu()
        self.label = QLabel('0', self)
        self.label.setGeometry(50, 200, 100, 80)
        self.label.setWordWrap(True)      # making label multiline
    def label_text(self):
        self.count += 1
        self.label.setText(self.count)

if __name__=='__main__':
    App = QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(App.exec())

Comments

Popular posts from this blog

QFormLayoutشرح ال

QGridLayoutشرح ال