QListWidget怎么设置列标题

QListWidget怎么设置列标题,第1张

QStandardItemModel model;
model=new QStandardItemModel ;
model->setHeaderData(0, Qt::Horizontal, tr("列标题1"));
model->setHeaderData(1, Qt::Horizontal, tr("列标题2"));
model->setHeaderData(2, Qt::Horizontal, tr("列标题3"));
model->setHeaderData(3, Qt::Horizontal, tr("列标题4"));
ui->testView->setModel(model);
其中testView就是QListwidget。MVC模式…… 楼主试试吧…… 我以前做这个的时候就是这么用的

有这样一个程序:#include <QtGui/QApplication> #include <qtextcodech>#include <QtGui/QDialog>#include <QtCore/QTimer>#include "widgeth"int main(int argc, char argv[]){ QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312")); QApplication a(argc, argv); QDialog dialog; dialogsetStyleSheet(QString::fromUtf8("background-image: url(:/images/1PNG);/n" "color: rgb(0, 255, 0);/n" "font: 75 16pt /"/345/256/213/344/275/223/";")); dialogsetGeometry(QRect(50, 50, 350, 250)); //可设置窗口显示的方位与大小 dialogsetWindowFlags(Qt::FramelessWindowHint); //也是去掉标题栏的语句 Widget w; QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(showNormal())); QObject::connect(&timer, SIGNAL(timeout()), &dialog, SLOT(accept())); timerstart(5000); dialogexec(); wshowNormal(); // 1、可更改的地方。 return aexec();} Widget::Widget(QWidget parent) : QWidget(parent){ QMessageBox::StandardButton message; QApplication::setStyle(QStyleFactory::create("plastique")); QApplication::setPalette(QApplication::style()->standardPalette()); uisetupUi(this); connect(uipushButton, SIGNAL(clicked()), this, SLOT(mountMessage())); connect(uipushButton_2, SIGNAL(clicked()), this, SLOT(umountMessage())); connect(uipushButton_3, SIGNAL(clicked()), this, SLOT(saveMessage())); connect(uipushButton_5, SIGNAL(clicked()), this, SLOT(adjustMessage())); connect(uipushButton_7, SIGNAL(clicked()), this, SLOT(about_usMessage())); connect(uipushButton_4, SIGNAL(clicked()), this, SLOT(stop_saveMessage())); connect(uipushButton_6, SIGNAL(clicked()), this, SLOT(touchMessage())); connect(uipushButton_8, SIGNAL(clicked()), this, SLOT(exitMessage())); mount_u(); //挂载U盘成功! if( !have_video() ) { //if have WebCam message = QMessageBox::information(this, tr("摄像头未连接"), tr("摄像头未连接,请连接摄像头。") ); } setWindowFlags(Qt::FramelessWindowHint); /2、可更改的地方 setWindowTitle(tr("欢迎使用迷你监控器!"));} 程序中更改两处显示主窗口的样式。

#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget parent = 0);
~Widget();
QPushButton clearNO,addNO;
QLabel label;
QHBoxLayout qhboxlayout;
private slots:
void clearNOhandle();
void addNOhandle();
};
#endif // WIDGET_H
///////////widgetcpp
#include "widgeth"
Widget::Widget(QWidget parent)
: QWidget(parent)
{
clearNO =new QPushButton("CLEAR");
addNO =new QPushButton("ADD");
label =new QLabel("0");
qhboxlayout =new QHBoxLayout(this);
qhboxlayout->addWidget(label);
qhboxlayout->addWidget(clearNO);
qhboxlayout->addWidget(addNO);
connect(clearNO,SIGNAL(clicked()),this,SLOT(clearNOhandle()));
connect(addNO,SIGNAL(clicked()),this,SLOT(addNOhandle()));
}
void Widget::addNOhandle(){
QString nostr;
int no;
nostr = label->text();
no = nostrtoInt();
no++;
nostrsetNum(no);
label->setText(nostr);
}
////////main函数
void Widget::clearNOhandle(){
label->setText("0");
}
Widget::~Widget()
{
}
#include <QtGui/QApplication>
#include "widgeth"
int main(int argc, char argv[])
{
QApplication a(argc, argv);
Widget w;
wshow();
return aexec();
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/13372581.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-23
下一篇 2023-07-23

发表评论

登录后才能评论

评论列表(0条)

保存