Qt学习笔记(单选框,复选框,按钮组,ListWidget)

#-------------------------------------------------
#
# Project created by QtCreator 2019-08-16T18:25:11
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 05_Control
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += \
    ../res.qrc
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include 

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
#include "mainwindow.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include 
#include 
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    //默认选女
    ui->woman->setChecked(true);



    //单选框打印内容
    connect(ui->woman,&QRadioButton::clicked,this,[=](){
        qDebug("女被选中了");
    });





    //多选框 选中后打印内容
    //选中2  未选中0   tristate 1状态

    //这块有一个它独有的属性 tristate 这个属性勾上以后,选项按钮组的返回值分别是0 1 2 1是半选状态。
    //stateChanged,返回值是int
    connect(ui->checkBox,&QCheckBox::stateChanged,this,[=](int state){
       qDebug()<listWidget->addItem(item0);
     ui->listWidget->addItem(item1);
      ui->listWidget->addItem(item2);
       ui->listWidget->addItem(item3);

    //设置对齐方式
    item0->setTextAlignment(Qt::AlignRight);//查文档

    //链表
    //QStringList ===== QLish
    QStringList list;
    list<< "锄禾日当午" <<"汗滴禾下土";

     ui->listWidget->addItems(list);
    //缺点无法设置对齐方式

     //匿名对象的方式。
     ui->listWidget->addItems(QStringList()<< "锄禾日当午" <<"汗滴禾下土");

}

MainWindow::~MainWindow()
{
    delete ui;
}


 MainWindow
 
  
   
    0
    0
    506
    369
   
  
  
   MainWindow
  
  
   
    
     
      10
      90
      91
      192
     
    
    
     GroupBox
    
    
     
      
       
        服务好
       
       
        true
       
      
     
     
      
       
        味道好
       
       
        false
       
      
     
     
      
       
        环境好
       
      
     
     
      
       
        老板娘好
       
      
     
     
      
       
        GroupBox
       
       
        
         
          
           
            
             
            
           
          
          
           
            
             
            
           
          
         
        
       
      
     
    
   
   
    
     
      170
      0
      256
      192
     
    
   
   
    
     
      10
      0
      77
      54
     
    
    
     
      
       
        登录
       
       
        
         ../Image/butterfly1.png../Image/butterfly1.png
       
      
     
     
      
       
        工具按钮
       
       
        
         ../Image/butterfly1.png../Image/butterfly1.png
       
      
     
    
   
  
  
   
    
     0
     0
     506
     23
    
   
  
  
   
    TopToolBarArea
   
   
    false
   
  
  
 
 
 
 

 

你可能感兴趣的:(Qt)