axylp123的个人主页

http://www.qtcn.org/bbs/u/154703  [收藏] [复制]

axylp123

  • 1

    关注

  • 1

    粉丝

  • 16

    访客

  • 等级:新手上路
  • 总积分:15
  • 男,1987-10-10

最后登录:2017-06-01

更多资料

日志

2.4.1 可扩展对话框

2015-11-27 13:14
//UISortDialog.h
#ifndef UISORTDIALOG_H
#define UISORTDIALOG_H
#include <QDialog>
namespace Ui {
    class UISortDialog;
}
class UISortDialog : public QDialog
{
    Q_OBJECT
public:
    explicit UISortDialog(QWidget *parent = 0);
    ~UISortDialog();
    void setColumnRange(QChar first, QChar last);
private:
    Ui::UISortDialog *ui;
};
#endif // UISORTDIALOG_H
//UISortDialog.cpp
#include "UISortDialog.h"
#include "ui_UISortDialog.h"
UISortDialog::UISortDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::UISortDialog)
{
    ui->setupUi(this);
    ui->m_pMoreBtn->setCheckable(true);
    //将窗体设置为固定大小
    layout()->setSizeConstraint(QLayout::SetFixedSize);
    ui->m_pSecondaryGroupBox->setVisible(false);
    ui->m_pTertiaryGroupBox->setVisible(false);
    connect(ui->m_pOKBtn, SIGNAL(clicked()), this, SLOT(accept()));
    connect(ui->m_pCancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
    connect(ui->m_pMoreBtn, SIGNAL(toggled(bool)), ui->m_pSecondaryGroupBox, SLOT(setVisible(bool)));
    connect(ui->m_pMoreBtn, SIGNAL(toggled(bool)), ui->m_pTertiaryGroupBox, SLOT(setVisible(bool)));
    setColumnRange('A', 'Z');
}
UISortDialog::~UISortDialog()
{
    delete ui;
}
void UISortDialog::setColumnRange(QChar first, QChar last)
{
    ui->m_pPrimaryColumnComBox->clear();
    ui->m_pSecondaryColumnCombox->clear();
    ui->m_pTertiaryColumnComBox->clear();
    ui->m_pSecondaryOrderComBox->addItem(tr("None"));
    ui->m_pTeritiaryOrderComBox->addItem(tr("None"));
    //sizeHint() 返回布局系统认为理想的大小
    ui->m_pPrimaryColumnComBox->setMinimumSize(ui->m_pPrimaryColumnComBox->sizeHint());
    ui->m_pSecondaryColumnCombox->setMinimumSize(ui->m_pSecondaryColumnCombox->sizeHint());
    ui->m_pTertiaryColumnComBox->setMinimumSize(ui->m_pTertiaryColumnComBox->sizeHint());
    QChar ch = first;
    while (ch <= last)
    {
        ui->m_pPrimaryColumnComBox->addItem(QString(ch));
        ui->m_pSecondaryColumnCombox->addItem(QString(ch));
        ui->m_pTertiaryColumnComBox->addItem(QString(ch));
        ch = ch.unicode() + 1;
    }
}
//main.cpp
#include <QtGui/QApplication>
#include "UISortDialog.h"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    UISortDialog w;
    int result = w.exec();
    if (result == QDialog::Accepted)
    {
        //确定按钮
    }
    else if(result == QDialog::Rejected)
    {
        //取消按钮
    }
    return a.exec();
}
//UISortDialog.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UISortDialog</class>
<widget class="QDialog" name="UISortDialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>262</width>
    <height>275</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>UISortDialog</string>
  </property>
  <layout class="QGridLayout" name="gridLayout_3">
   <item row="0" column="0">
    <widget class="QGroupBox" name="m_pPrimaryGroupBox">
     <property name="title">
      <string>&Primary Key</string>
     </property>
     <layout class="QGridLayout" name="gridLayout">
      <item row="0" column="0">
       <widget class="QLabel" name="label">
        <property name="text">
         <string>Column:</string>
        </property>
       </widget>
      </item>
      <item row="0" column="2">
       <spacer name="horizontalSpacer">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>59</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="1" column="0">
       <widget class="QLabel" name="label_2">
        <property name="text">
         <string>Order:</string>
        </property>
       </widget>
      </item>
      <item row="1" column="1" colspan="2">
       <widget class="QComboBox" name="m_pPrimaryOrderCombox">
        <item>
         <property name="text">
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QComboBox" name="m_pPrimaryColumnComBox">
        <item>
         <property name="text">
          <string>Node</string>
         </property>
        </item>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
   <item row="0" column="1">
    <layout class="QVBoxLayout" name="verticalLayout">
     <item>
      <widget class="QPushButton" name="m_pOKBtn">
       <property name="text">
        <string>OK</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="m_pCancelBtn">
       <property name="text">
        <string>Cancel</string>
       </property>
      </widget>
     </item>
     <item>
      <spacer name="verticalSpacer">
       <property name="orientation">
        <enum>Qt::Vertical</enum>
       </property>
       <property name="sizeHint" stdset="0">
        <size>
         <width>20</width>
         <height>0</height>
        </size>
       </property>
      </spacer>
     </item>
     <item>
      <widget class="QPushButton" name="m_pMoreBtn">
       <property name="text">
        <string>&More</string>
       </property>
      </widget>
     </item>
    </layout>
   </item>
   <item row="1" column="0">
    <widget class="QGroupBox" name="m_pSecondaryGroupBox">
     <property name="title">
      <string>&Secondary Key</string>
     </property>
     <layout class="QGridLayout" name="gridLayout_2">
      <item row="0" column="0">
       <widget class="QLabel" name="label_3">
        <property name="text">
         <string>Column:</string>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QComboBox" name="m_pSecondaryColumnCombox">
        <item>
         <property name="text">
          <string>Node</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="2">
       <spacer name="horizontalSpacer_2">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>59</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="1" column="0">
       <widget class="QLabel" name="label_4">
        <property name="text">
         <string>Order:</string>
        </property>
       </widget>
      </item>
      <item row="1" column="1" colspan="2">
       <widget class="QComboBox" name="m_pSecondaryOrderComBox">
        <item>
         <property name="text">
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
   <item row="2" column="0">
    <widget class="QGroupBox" name="m_pTertiaryGroupBox">
     <property name="title">
      <string>&Primary Key</string>
     </property>
     <layout class="QGridLayout" name="gridLayout_4">
      <item row="0" column="0">
       <widget class="QLabel" name="label_5">
        <property name="text">
         <string>Column:</string>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QComboBox" name="m_pTertiaryColumnComBox">
        <item>
         <property name="text">
          <string>Node</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="2">
       <spacer name="horizontalSpacer_3">
        <property name="orientation">
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>59</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
      <item row="1" column="0">
       <widget class="QLabel" name="label_6">
        <property name="text">
         <string>Order:</string>
        </property>
       </widget>
      </item>
      <item row="1" column="1" colspan="2">
       <widget class="QComboBox" name="m_pTeritiaryOrderComBox">
        <item>
         <property name="text">
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text">
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
  </layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

分类:C++GUIQt4|回复:0|浏览:810|全站可见|转载
 

Powered by phpwind v8.7 Certificate Copyright Time now is:12-07 04:53
©2005-2016 QTCN开发网 版权所有 Gzip disabled