改变形状的对话框

Qt: QPushButton的checkable属性

选中checkable后,Button变成切换按钮(toggle button),可以有两种状态:按下/弹起

默认状况下checkable是不选中的,Button默认为触发按钮(trigger button),按下去马上弹起来


群组框:group box  
组合框:combobox


点击ctrl再点击窗体移动  就可以进行复制操作


toggle(bool)开关信号  比click()信号多传递一个参数!

设计的窗体结构图为:

改变形状的对话框_第1张图片

在组合框内选择栅格布局,整个布局选择栅格布局


dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include 

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT
    
public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    void setColumnRange(QChar first,QChar last);

private slots:
    void setText(bool &b);
    
private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H

dialog.cpp

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    connect(ui->moreButton,SIGNAL(toggled(bool)),this,SLOT(setText(bool)));
    ui->secondaryGoupBox->hide();
    ui->tertiaryGoupBox->hide();
    //对窗体大小进行限制
    //不能因为隐藏窗体而修改窗体的大小 确保对话框显示最佳尺寸
    layout()->setSizeConstraint(QLayout::SetFixedSize);
    setColumnRange('A','Z');
}

void Dialog::setText(bool &b)
{
    if(b == TRUE)
    {
        this->ui->moreButton->setText(tr("Advanced >>"));
    }
    else
    {
        this->ui->moreButton->setText(tr("Advanced <<"));
    }
}

void Dialog::setColumnRange(QChar first,QChar last)
{
    ui->primaryColumnCombo->clear();
    ui->secondaryColumnCombo->clear();
    ui->tertiaryColumnCombo->clear();

    ui->secondaryColumnCombo->addItem(tr("None"));
    ui->tertiaryColumnCombo->addItem(tr("None"));
    ui->primaryColumnCombo->setMinimumSize(ui->secondaryColumnCombo->sizeHint());

    QChar ch = first;
    while(ch <= last)
    {
        ui->primaryColumnCombo->addItem(QString(ch));
        ui->secondaryColumnCombo->addItem(QString(ch));
        ui->tertiaryColumnCombo->addItem(QString(ch));
        ch = ch.unicode() + 1;
    }

}

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

main.cpp

#include "mainwindow.h"
#include 
#include "ui/dialog.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();
    return a.exec();
}




你可能感兴趣的:(QT学习)