zoukankan      html  css  js  c++  java
  • QT的组件布局

    在QT的IDE下,编写一个自定义布局。

     1 #include<QApplication>
     2 #include<QWidget>
     3 #include<QSpinBox>
     4 #include<QSlider>
     5 #include<QHBoxLayout>
     6 
     7 int main (int argc,char *argv[])
     8 {
     9     QApplication app(argc, argv);
    10     QWidget * window = new QWidget;
    11     window->setWindowTitle("ENTER your age");
    12     QSpinBox *spinBox = new QSpinBox;
    13     QSlider *slider = new QSlider(Qt::Horizontal);
    14     spinBox->setRange(0,130);
    15     slider->setRange(0,130);
    16     QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
    17     QObject::connect(spinBox,SIGNAL(valueChanged(int)),slider,SLOT(setValue(int)));
    18     spinBox->setValue(35);
    19     QHBoxLayout*layout=new QHBoxLayout;
    20     layout->addWidget(spinBox);
    21     layout->addWidget(slider);
    22     window->setLayout(layout);
    23     window->show();
    24     return app.exec();
    25 }

    在qt creater 运行结果,如下

    用两个信号槽进行连接,QHBoxLayout是一个水平布局,按照从左向右的方向添加。

    这两个信号槽不会无限递归,因为回调回来的int值相同,就不会继续发生信号了。

    QT的三个布局,QHBoxLayout,水平布局,从左向右。

                             QVBoxLayout,垂直布局,从上到下。

                              QGridLayout,网状布局。

                         layout使用addWidget加载组件,使用addLayout添加子布局。

  • 相关阅读:
    redis概要学习
    http协议格式详解
    浅谈mysql
    linux常用命令
    Linux 程序管理
    认识与分析日志文件
    认识与学习bash
    例行任务管理
    软件安装的三大方法
    关于一些感慨
  • 原文地址:https://www.cnblogs.com/132818Creator/p/7207692.html
Copyright © 2011-2022 走看看