3.treewidget QTreeWidgetItem *issuer1 = new QTreeWidgetItem(m_ui->treeWidget); issuer1->setText(0, tr("发卡方1")); QTreeWidgetItem *merchant1 = new QTreeWidgetItem(issuer1); merchant1->setText(0, tr("商户1")); merchant1->setText(1, tr("Yes")); QTreeWidgetItem *outlet1 = new QTreeWidgetItem(merchant1); outlet1->setText(0, tr("网点1")); outlet1->setText(1, tr("Yes")); QTreeWidgetItem *outlet2 = new QTreeWidgetItem(merchant1); outlet2->setText(0, tr("网点2")); outlet2->setText(1, tr("Yes")); QTreeWidgetItem *merchant2 = new QTreeWidgetItem(issuer1); merchant2->setText(0, tr("商户2")); merchant2->setText(1, tr("Yes")); 4.tablewidget(每次修改后重新显示表) #include
显示table: m_ui->tableWidget_2->setRowCount(2); m_ui->tableWidget_2->setItem(0,1,new QTableWidgetItem(tr("123"))); m_ui->tableWidget_2->setItem(1,1,new QTableWidgetItem(tr("12"))); 取某值: g_select_key[j]=atoi(m_ui->tableWidget->item(temp[j],0)->text().toAscii().data()); 选中行: QItemSelectionModel *m = m_ui->tableWidget_2->selectionModel(); QModelIndexList indexes = m->selectedIndexes(); QModelIndex index; int temp[11]={0}; int which_row[11]={0}; int i=0; int count_no = 10; foreach(index,indexes){ temp[i++]= index.row(); } if(i==0) QMessageBox::warning(this,tr("警告"),tr("请先选中一行")); else if(i==1) { which_row[0]=temp[0]; if(which_row[0]>=count_no) QMessageBox::warning(this,tr("警告"),tr("选择有误")); else { cout<<"修改。。。"<
tableWidget_2->setItem(1,1,new QTableWidgetItem(tr("12"))); m_ui->tableWidget_2->setItem(2,1,new QTableWidgetItem(tr("12"))); } } else if(i>1) { int j; for(j=1;j
=count_no) QMessageBox::warning(this,tr("警告"),tr("选择有误")); else { cout<<"修改。。。"<
tableWidget_2->setItem(1,1,new QTableWidgetItem(tr("12"))); m_ui->tableWidget_2->setItem(2,1,new QTableWidgetItem(tr("12"))); } } else QMessageBox::warning(this,tr("警告"),tr("一次只能修改一行")); } else return; 5.comboBox #include
for( i=0; i
merchant_comboBox->addItem(QString::fromUtf8(short_name[i])); merchant_name=ui->merchant_comboBox->currentText();//comboBox start_date=ui->start_dateEdit->text();//dateEdit end_date=ui->end_dateEdit->text(); report_type=ui->type_comboBox->currentText(); s=ui->merchants_comboBox->itemText(i);// 6.登录框(http://hi.baidu.com/yafeilinux/blog/item/a335cd10a465d174cb80c42d.html) QApplication a(argc, argv); Widget w; loginDlg login; if(login.exec()==QDialog::Accepted) { w.show(); return a.exec(); } else return 0; // if(m_ui->usrlineEdit->text()==tr("hqq")&&m_ui->pwdlineEdit->text()==tr("hqq")) //判断用户名和密码是否正确 accept(); else{ QMessageBox::warning(this,tr("Warning"),tr("user name or password error!"),QMessageBox::Yes); //如果不正确,弹出警告对话框 m_ui->usrlineEdit->clear();//清空用户名输入框 m_ui->pwdlineEdit->clear();//清空密码输入框 m_ui->usrlineEdit->setFocus();//将光标转到用户名输入框 } 7.横向滚动条和spinBox关联使用 ui->spinBox->setRange(0, 130);//设置各自的取值范围 ui->horizontalSlider->setRange(0, 130); //滑块和Spin组件的值的变化都会对应的改变 QObject::connect(ui->spinBox, SIGNAL(valueChanged(int)), ui->horizontalSlider, SLOT(setValue(int))); QObject::connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), ui->spinBox, SLOT(setValue(int))); ui->spinBox->setValue(35);//注意这里的设置也会影响slider 8.progressbar的使用(点击按钮触发progressbar,而不是触发整个界面) for (i=1;i<=100;i++) { m_ui->progressbar->setValue(i); for ( j=0; j<1000*1000*4;j++) { } } 9.mdi:在Qt中要制作MDI介面的视窗,是使用QMainWindow ,并将其中心元件(Central Widget)设为QMdiArea实例,而每一个MDI子视窗,则使用QMdiArea的addSubWindow()来加入。 #include
在on_actionNew_N_triggered()中: QMdiArea *mdiArea = new QMdiArea; this->setCentralWidget(mdiArea); QTextEdit *textEdit = new QTextEdit; textEdit->setWindowTitle("File1"); mdiArea->addSubWindow(textEdit); 10.connect(sender, signal, receiver, member) sender是发生器,signal是发出的信号,receiver是接收器,member是槽。 如:connect(hostLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(enableGetFortuneButton())); 11.设置可编辑状态 for(j=0;j
tableWidget->item(i,19)->setFlags(Qt::ItemIsEditable); 12.QMessageBox if(QMessageBox::information(this,tr("警告"),tr("确定删除?"),QMessageBox::No,QMessageBox::Yes)==16384) 13.QFile QFile file("/home/hqq/1.txt"); char *msg="1234"; file.open( QIODevice::WriteOnly); file.write(msg, qstrlen(msg)); file.close(); 14.execl QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),"",tr("file(*.CSV)")); cout<<"fileName="<
<
fromUnicode(fileName).data(); FILE *fileWrite = fopen( strbuffer.c_str(),"w+"); QString strFemale = "Female "; QString strMale = "Male "; QString strPatientCount = "Patient "; char a[20]="abc"; char b[20]="一二三"; QString str ="/n"; //std::string strCountbuffer = code->fromUnicode(strFemale+","+strMale+","+strPatientCount+str+QString().setNum(femaleCount)+","+QString().setNum(maleCount)+","+QString().setNum(patientCount)).data(); //std::string strCountbuffer=code->fromUnicode(strFemale+","+strMale+","+strPatientCount+str+QString().setNum(1)+","+QString().setNum(1)+","+QString().setNum(1)).data(); //std::string strCountbuffer=code->fromUnicode(strFemale+strMale+strPatientCount+str+QString().setNum(1)).data();//可用 std::string strCountbuffer=code->fromUnicode(strFemale+strMale+strPatientCount+str+a+' '+tr(b)).data(); QFile file; file.open(fileWrite, QIODevice::WriteOnly); file.write(strCountbuffer.c_str(), qstrlen(strCountbuffer.c_str())); file.close(); 15.打印 #include
#include
#include
#include
#include
QTextDocument *document = ui->textEdit->document(); QPrinter printer; QPrintDialog dlg(&printer, this); dlg.setWindowTitle(tr("打印文档")); if (dlg.exec() != QDialog::Accepted) return; document->print(&printer);
QT相关
最新推荐文章于 2023-05-10 14:46:39 发布