zoukankan      html  css  js  c++  java
  • QT5控件-QPushButton和QFocusFrame(按钮和焦点框)

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QPushButton>
    #include <QFocusFrame>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
        QPushButton* btn[10];
        QFocusFrame* btn_frame ;
    public slots:
        void btn_clicked();
    };
    
    #endif // MAINWINDOW_H
    #include "mainwindow.h"
    #include <QtDebug>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        this->resize(400,300);
        this->centralWidget();
    
        int ypos = 30 ;
    
        for(int i=0;i<3;i++)
        {
            btn[i] = new QPushButton(QString("第%1个按钮").arg(i),this);
            btn[i]->setGeometry(10,ypos,300,40);
    
            ypos += 50 ;
        }
    
        for(int i=0;i<3;i++)
        {
            connect(btn[i],SIGNAL(clicked(bool)),SLOT(btn_clicked()));
        }
    
        btn_frame = new QFocusFrame(this);
        btn_frame->setWidget(btn[0]);
        btn_frame->setAutoFillBackground(true);
    }
    
    MainWindow::~MainWindow()
    {
    
    }
    
    void MainWindow::btn_clicked()
    {
        qDebug()<<"触发clicked事件";
    }
    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }

    QFocusFrame也可以将其他控件包含在里面

  • 相关阅读:
    install ros-indigo-tf2
    install ros-indigo-tf
    install diagnostic_updater
    install ros-indigo-ecl-build
    "CMAKE_CXX_COMPILER-NOTFOUND"
    shell 交互式选择(select)
    install ros indigo tf2
    a标签 在新页面打开
    bootstrap.min.css.map HTTP/1.1" 404 1699
    E: Sub-process /usr/bin/dpkg returned an error code (1)
  • 原文地址:https://www.cnblogs.com/shiyumiao/p/5207736.html
Copyright © 2011-2022 走看看