QComboBox 编辑组合框
来源:互联网 发布:电子相册软件app软件 编辑:程序博客网 时间:2024/05/17 00:50
在编辑QComboBox的时候,看到编辑组合框,看到这种窗口挺好,
想自己试试,一上手才发现自己有多菜
好在最后还是实现了
#ifndef COMBOBOXEDITDIALOG_H#define COMBOBOXEDITDIALOG_H#include <QDialog>class QToolButton;class QListWidget;class QTreeWidget;class ComboBoxEditDialog : public QDialog{ Q_OBJECTpublic: explicit ComboBoxEditDialog(QWidget *parent = 0);signals:public slots: void switchState();private: void init();private: QListWidget *m_listWidget; QTreeWidget *m_treeWidget; QToolButton *m_addBtn; QToolButton *m_redBtn; QToolButton *m_upBtn; QToolButton *m_downBtn; QPushButton *m_attriBtn; QWidget *rightWidget;};#endif // COMBOBOXEDITDIALOG_H
#include "comboboxeditdialog.h"#include <QtGui>ComboBoxEditDialog::ComboBoxEditDialog(QWidget *parent) : QDialog(parent){ init();}void ComboBoxEditDialog::init(){ m_listWidget = new QListWidget; m_treeWidget = new QTreeWidget; m_treeWidget->setColumnCount(2); m_treeWidget->setHeaderLabels(QStringList()<<"attribute"<<"value");; m_addBtn = new QToolButton(); m_addBtn->setIcon(QIcon(":/pics/plus-16.png")); m_redBtn = new QToolButton(); m_redBtn->setIcon(QIcon(":/pics/minus-16.png")); m_upBtn = new QToolButton(); m_upBtn->setIcon(QIcon(":/pics/up.png")); m_downBtn= new QToolButton(); m_downBtn->setIcon(QIcon(":/pics/down.png")); m_attriBtn = new QPushButton("属性<<"); connect(m_attriBtn,SIGNAL(clicked()),this,SLOT(switchState())); QHBoxLayout *btnLayout1 = new QHBoxLayout(); btnLayout1->addWidget(m_addBtn,-1,Qt::AlignLeft); btnLayout1->addWidget(m_redBtn,-1,Qt::AlignLeft); btnLayout1->setContentsMargins(0,0,0,0); btnLayout1->setSpacing(0); btnLayout1->addStretch(10); btnLayout1->addWidget(m_upBtn,-1,Qt::AlignHCenter); btnLayout1->addWidget(m_downBtn,-1,Qt::AlignHCenter); btnLayout1->addStretch(10); btnLayout1->addWidget(m_attriBtn,-1,Qt::AlignRight); QVBoxLayout *leftUpLayout = new QVBoxLayout(); leftUpLayout->addWidget(m_listWidget); leftUpLayout->addLayout(btnLayout1); leftUpLayout->setContentsMargins(0,0,0,0); QWidget *leftUpWidget = new QWidget(); leftUpWidget->setLayout(leftUpLayout); leftUpWidget->setContentsMargins(0,0,0,0); rightWidget = new QWidget(); QVBoxLayout *rightLayout = new QVBoxLayout(); rightLayout->addWidget(m_treeWidget); rightLayout->setContentsMargins(0,0,0,0); rightLayout->setSpacing(0); rightWidget->hide(); rightWidget->setLayout(rightLayout); QSplitter* splitter = new QSplitter(Qt::Horizontal); splitter->addWidget(leftUpWidget); splitter->addWidget(rightWidget); QDialogButtonBox *box = new QDialogButtonBox(); box->addButton("确定",QDialogButtonBox::AcceptRole); box->addButton("取消",QDialogButtonBox::RejectRole); QFrame *lineWidget = new QFrame(); lineWidget->setFrameShape(QFrame::HLine); lineWidget->setFrameShadow(QFrame::Sunken); QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addWidget(splitter); mainLayout->addWidget(lineWidget); mainLayout->addWidget(box); this->setLayout(mainLayout); this->resize(500,300);}void ComboBoxEditDialog::switchState(){ if(rightWidget->isVisible()) { rightWidget->hide(); m_attriBtn->setText(tr("属性<<")); }else { rightWidget->show(); m_attriBtn->setText(tr("属性>>")); }}欢迎拍砖
- QComboBox 编辑组合框
- QComboBox 编辑组合框
- QComboBox 编辑组合框
- QCombobox组合框的样式
- 组合框QComboBox的定制
- 组合框QComboBox的定制
- QComboBox的代理(订制QComboBox组合框)
- QCombobox组合框 样式表 举例
- QComboBox组合框 自定义样式 item的高度
- QT - qss(二)组合框QComboBox的定制
- Qt基础学习(4)-----下拉列表框(组合框)之QComboBox
- Qt基础学习-----下拉列表框(组合框)之QComboBox
- Qt Style Sheet实践(二):组合框QComboBox的定制
- qt QComboBox 组合框 的currentIndexChanged ( int index )信号的触发
- Qt Style Sheet实践(二):组合框QComboBox的定制
- 编辑框与状态栏组合
- QComboBox
- QComboBox
- 如何编译成.so动态库?
- You have new mail in /var/spool/mail/root
- unixODBC中 column .... does not exist 的解决过程
- 让MacBook/MacBookPro成为WiFi热点
- Linux下创建和使用RamDisk的技巧
- QComboBox 编辑组合框
- UITextField监听文字输入事件
- 解决google访问问题
- 完全数的性质
- 正则表达式30分钟入门教程
- 马云关于国事
- 虚拟机Fedora 9与windows xp 共享文件
- redhat和Ubuntu网络配置文件
- qt 正则表达式