qt实现自定义对话框

本文介绍了如何在QT中实现一个自定义对话框,该对话框支持静态对象调用,确保在对话框阻塞状态下只有一个界面显示,从而达到对象复用。通过QBaseDialog::showDialog或直接创建dialog对象调用execDialog方法,可以方便地在应用程序中使用这个自定义对话框。示例代码基于自定义窗体,但也适用于其他基类。

功能特点:

1.支持以静态对象的方式调用,由于对话框阻塞的特性,所以只会有一个界面被显示,从而实现了一个对象重复使用的目的。

2.本示例是基于自定义窗体实现的,也可以修改为其它基类实现。

调用方式:

QBaseDialog::showDialog(this, _text, _title, _buttonType);

或者

QBaseDialog dialog;

dialog.execDialog(this,"this is dialog","hint");

界面文件:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>QBaseDialog</class>
 <widget class="QBaseWindow" name="QBaseDialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>240</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <widget class="QWidget" name="layoutWidget">
   <property name="geometry">
    <rect>
     <x>11</x>
     <y>10</y>
     <width>371</width>
     <height>221</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <widget class="QLabel" name="LE_Icon">
      <property name="minimumSize">
       <size>
        <width>40</width>
        <height>40</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>40</width>
        <height>40</height>
       </size>
      </property>
      <property name="text">
       <string>icon</string>
      </property>
     </widget>
    </item>
    <item row="0" column="1" colspan="4">
     <widget cla
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值