当前位置:网站首页>Preliminary understanding of qtoolbutton

Preliminary understanding of qtoolbutton

2022-06-25 01:02:00 PureヾChan

 

Today, it is implemented in code ui Some buttons in the interface , But I haven't seen many . for instance QToolButton, In fact, it is also a button , But it can be like a button in a drop-down menu , But format it .

for example :

 QToolButton* toolBtn=new QToolButton(this);
    toolBtn->setText(" Color ");

    // Define a new menu 
    QMenu *colorMenu=new QMenu(this);
    colorMenu->addAction(" Red ");
    colorMenu->addAction(" Blue ");
    // Pass menu in QToolBar As a parameter , Link menus to buttons 
    toolBtn->setMenu(colorMenu);
    toolBtn->setPopupMode(QToolButton::MenuButtonPopup);// Set the button pop-up mode 
    ui->mainToolBar->addWidget(toolBtn);

Based on mainWindow Add these functions to the constructor of the class , It's about building a QToolButton Then set the text to color . Then you can build a menu , Add inside Action, Then it can be passed to QToolButton, Then set the pop-up mode of the menu to press pop-up , If not set , There will be no pop-up operation . Because it's not Action So the toolbar is added with addWidget operation .

Icon :

原网站

版权声明
本文为[PureヾChan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210545036910.html