QT5.14.2 官方例子 - Qt Widgets 7: Group Box(组合框)

组框示例展示了如何在Qt中使用不同类型的组框。

组框是容器小部件,可以在逻辑上和屏幕上将按钮组织成组。它们管理用户和应用程序之间的交互,因此您不必强制执行简单的约束。

组框通常用于将复选框和单选按钮组织到独占组中。


组框示例由单个窗口类组成,用于显示四个组框:独占单选按钮组、非独占复选框组、具有启用复选框的独占单选按钮组和具有普通按钮的组框。

 

详细讲解:

https://doc.qt.io/qt-5/qtwidgets-widgets-groupbox-example.html

 

Window类是QWidget的一个子类,用于显示许多组框。类定义包含构造每个组框的函数,并使用按钮小部件的不同选择来填充它:

class Window : public QWidget
  {
      Q_OBJECT

  public:
      Window(QWidget *parent = nullptr);

  private:
      QGroupBox *createFirstExclusiveGroup();
      QGroupBox *createSecondExclusiveGroup();
      QGroupBox *createNonExclusiveGroup();
      QGroupBox *createPushButtonGroup();
  };

在本例中,小部件将用作顶级窗口,因此定义了构造函数,这样我们就不必指定父小部件。

 

收获点:

1.设置组合框是否可编辑;

第二个组框本身是可选中的,提供了一种禁用其中所有按钮的方便方法。最初,它是未选中的,因此必须先选中组框本身,然后才能选中其中的任何单选按钮。

QGroupBox *Window::createSecondExclusiveGroup()
  {
      QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
      groupBox->setCheckable(true);
      groupBox->setChecked(false);

设置组合框为“扁平”模式:

第三个组框是用“扁平”样式构造的,这种样式更适合于某些类型的对话框。

QGroupBox *Window::createNonExclusiveGroup()
  {
      QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes"));
      groupBox->setFlat(true);

 

2.设置QCheckbox为三状态复选框:

 QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
      tristateBox->setTristate(true);

 

3.设置QPushbutton为可检查的,以及“扁平”式:

      QPushButton *pushButton = new QPushButton(tr("&Normal Button"));
      QPushButton *toggleButton = new QPushButton(tr("&Toggle Button"));
      toggleButton->setCheckable(true);
      toggleButton->setChecked(true);
      QPushButton *flatButton = new QPushButton(tr("&Flat Button"));
      flatButton->setFlat(true);

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Command line: -prefix /home/liuyh/workspace/qt5.14.2-arm -opensource -confirm-license -release -strip -shared -xplatform linux-arm-gnueabi-g++ -optimized-qmake -c++std c++11 --rpath=no -pch -skip qt3d -skip qtactiveqt -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad -skip qtlocation -skip qtmacextras -skip qtnetworkauth -skip qtpurchasing -skip qtremoteobjects -skip qtscript -skip qtscxml -skip qtsensors -skip qtspeech -skip qtsvg -skip qttools -skip qttranslations -skip qtwayland -skip qtwebengine -skip qtwebview -skip qtwinextras -skip qtx11extras -skip qtxmlpatterns -make libs -make examples -nomake tools -nomake tests -gui -widgets -dbus-runtime --glib=no --iconv=no --pcre=qt --zlib=qt -no-openssl --freetype=qt --harfbuzz=qt -no-opengl -linuxfb --xcb=no -tslib --libpng=qt --libjpeg=qt --sqlite=qt -plugin-sql-sqlite -I/opt/tslib/include -L/opt/tslib/lib -recheck-all executing config test machineTuple + arm-linux-gnueabi-g++ -dumpmachine > sh: 1: arm-linux-gnueabi-g++: not found test config.qtbase.tests.machineTuple FAILED executing config test verifyspec + cd /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/config.tests/verifyspec && /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" 'QMAKE_LIBDIR += /opt/tslib/lib' 'INCLUDEPATH += /opt/tslib/include' -early "CONFIG += cross_compile" /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec + cd /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/config.tests/verifyspec && MAKEFLAGS= /usr/bin/make clean && MAKEFLAGS= /usr/bin/make > rm -f verifyspec.o > rm -f *~ core *.core > arm-linux-gnueabi-g++ -c -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard -O2 -march=armv7-a -mtune=cortex-a7 -mfpu=neon -mfloat-abi=hard -pipe -O2 -w -fPIC -I/home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec -I. -I/opt/tslib/include -I/home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/mkspecs/linux-arm-gnueabi-g++ -o verifyspec.o /home/liuyh/workspace/QT5.14.2/qt-everywhere-src-5.14.2/qtbase/config.tests/verifyspec/verifyspec.cpp > make:arm-linux-gnueabi-g++:命令未找到 > make: *** [Makefile:172:verifyspec.o] 错误 127
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值