异度部落格

学习是一种生活态度。

0%

本来是将硬盘分成两块,然后装双系统的。可是最近grub老师挂掉,然后就又要修复xp的启动实在太麻烦了

所以改用wubi来装,可是安装的过程中出现一直停留在creating the virual disks那里,无法进行下去。

解决方法如下:这个问题是由于文件系统造成的,本来我是用fat32的,不能创建虚拟文件系统,后来格式化为ntfs就可以了。(这个难道跟MS那次fat专利起诉案由关??)

顺便补充下:要是系统有装ghost的,最好先删除,不然可能会出现启动时候会有乱码问题,应是说是根本进不去…..貌似8.04有这个问题,不知道9.04有没

安装完以后编译 Qt 程序出现错误: No valid Qt version set. Set one in Tools/Options

查看 Tools/Options 重装也是这样的….

解决方案如下: 安装时关闭杀毒软件,我用的是 KAV 8 不知道会不会是这个问题 PS:貌似安装 Ecilipse 的 Qt 插件也会遇到一些 dll 模块无法注入的问题,解决方案相同

咱习惯用遨游了,所以习惯双击标签栏,firefox 默认是没有这个功能的,需要一个插件,

下载插件:Tab Mix Plus

首选项-> 鼠标点击 -> 双击左键 设置如下: 标签页上:关闭标签页 标签栏上:打开新标签页

或者

下载: Tab mix lite ce

这个就不用设置了,默认就可以了,咱推荐用这个,nice

这次写了一个简单的 Icon 编辑器,功能很简单的说.....详见代码

=================================================================

iconeditor.h

#ifndef ICONEDITOR_H
#define ICONEDITOR_H
#include <QtGui/QWidget>
#include <QImage>
#include <QWidget>
class IconEditor : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor penColor READ penClor WRITE setPenColor);
Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage);
Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor);
public:
IconEditor(QWidget *parent = 0);
~IconEditor();
void setPenColor(const QColor &newColor);
QColor penColor();
void setZoomFactor(int newZoom);
int zoomFactor() const;
void setIconImage(const QImage &newImage);
QImage iconImage() const;
QSize sizeHint() const;
protected:
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void paintEvent(QPaintEvent *event);
private:
void setImagePixel(const QPoint &pos,bool opaque);
QRect pixelRect(int i,int j) const;
QColor curColor;
QImage image;
int zoom;
};
#endif // ICONEDITOR_H

iconeditor.cpp

#include<QtGui>
#include "iconeditor.h"
IconEditor::IconEditor(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_StaticContents);
setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
curColor=Qt::black;
zoom=8;
image=QImage(16,16,QImage::Format_ARGB32);
image.fill(qRgba(0,0,0,0));
}
/*
Qt::WA_StaticContents 用法:
Indicates that the widget contents are north-west aligned and static.
On resize, such a widget will receive paint events only for parts of itself
that are newly visible. This flag is set or cleared by the widget's author.
*/
IconEditor::~IconEditor()
{
}
void IconEditor::setPenColor(const QColor &newColor)
{
curColor=newColor;
}
QColor IconEditor::penColor()
{
return curColor;
}
void IconEditor::setZoomFactor(int newZoom)
{
if(newZoom<1)
newZoom=1;
if(newZoom!=zoom){
zoom=newZoom;
this->update();
this->updateGeometry(); //调用update和updateGeometry进行重绘
}
}
int IconEditor::zoomFactor() const
{
return zoom;
}
void IconEditor::setIconImage(const QImage &newImage)
{
if(newImage!=image){
image=newImage.convertToFormat(QImage::Format_ARGB32);
this->update();
this->updateGeometry();
}
}
QImage IconEditor::iconImage() const
{
return image;
}
QSize IconEditor::sizeHint() const
{
QSize size=zoom*image.size();
if(zoom>=3)
size+=QSize(1,1); //当zoom>=3时,增加一个像素用存放网格线
return size;
}
/*只要重绘就会调用这个函数*/
void IconEditor::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
if(zoom>=3){
painter.setPen(palette().foreground().color());
//绘制垂直表格线
for(int i=0;i<=image.height();++i)
painter.drawLine(zoom*i,0,zoom*image.width(),zoom*i); //(x1,y1) to (x2,y2)
//绘制水平表格线
for(int j=0;j<image.width();++j)
painter.drawLine(0,zoom*j,zoom*image.width(),zoom*j);
}
for(int i=0;i<image.width();++i){
for(int j=0;j<image.height();++j){
QRect rect=pixelRect(i,j);
if(!event->region().intersect(rect).isEmpty()){ //region区域
QColor color=QColor::fromRgba(image.pixel(i,j)); //pixel(x,y)返回(x,y)的一个像素
if(color.alpha()<255)
painter.fillRect(rect,Qt::white);
painter.fillRect(rect,color);
}
}
}
}
QRect IconEditor::pixelRect(int i,int j) const
{
if(zoom>=3){
return QRect(zoom*i+1,zoom*j+1,zoom-1,zoom-1);
}else{
return QRect(zoom*i,zoom*j,zoom,zoom); //QRect其中一种构造函数,QRect ( int x, int y, int width, int height )
}
}
void IconEditor::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton){
setImagePixel(event->pos(),true);
}else if(event->button()==Qt::RightButton){
setImagePixel(event->pos(),false);
}
}
void IconEditor::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons()& Qt::LeftButton){ //用Qt::LeftButton与buttons位或
setImagePixel(event->pos(),true);
}else if(event->buttons()& Qt::RightButton){
setImagePixel(event->pos(),false);
}
}
void IconEditor::setImagePixel(const QPoint &pos,bool opaque)
{
int i=pos.x()/zoom;
int j=pos.y()/zoom;
if(image.rect().contains(i,j)){
if(opaque){
image.setPixel(i,j,penColor().rgba());
}else{
image.setPixel(i,j,qRgba(0,0,0,0));
}
}
update(pixelRect(i,j));
}

main.cpp

#include <QtGui/QApplication>
#include "iconeditor.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
IconEditor *iconEditor=new IconEditor;
iconEditor->setWindowTitle("Icon Editor");
iconEditor->setIconImage(QImage(":/images/qt-logo.png"));
iconEditor->show();
return app.exec();
}

PS:貌似无话可说

这个程序主要为了,练习自定义 Qt 窗体部件,HexSpinBox 实现了一个 16 进制的 SpinBox,所以只要重载 SpinBox 就可以了...详见代码

==================================================================

hexspinbox.h

#ifndef HEXSPINBOX_H
#define HEXSPINBOX_H
#include <QtGui/QWidget>
#include <QSpinBox>
namespace Ui
{
class HexSpinBoxClass;
}
class HexSpinBox : public QSpinBox //继承QSpinBox 控件
{
Q_OBJECT
public:
HexSpinBox(QWidget *parent = 0);
~HexSpinBox();
protected:
QValidator::State validate(QString &text,int &pos) const;
int valueFromText(const QString &text) const; //virtual函数必须重载
QString textFromValue(int value) const; //virtual函数必须重载
private:
Ui::HexSpinBoxClass *ui;
QRegExpValidator *validator;
};
#endif // HEXSPINBOX_H

hexspinbox.cpp

#include "hexspinbox.h"
#include "ui_hexspinbox.h"
HexSpinBox::HexSpinBox(QWidget *parent)
:QSpinBox(parent)
{
ui->setupUi(this);
setRange(0,255);
validator=new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,8}"),this);
}
HexSpinBox::~HexSpinBox()
{
delete ui;
}
/*检查用户输入的合法性*/
QValidator::State HexSpinBox::validate(QString &text,int &pos) const
{
return validator->validate(text,pos);
}
/*整型值转换为16进制的字符串*/
QString HexSpinBox::textFromValue(int value) const
{
return QString::number(value,16).toUpper();
}
/*字符串到整数值,若字符串合法ok返回true,否则返回false*/
int HexSpinBox::valueFromText(const QString &text) const
{
bool ok;
return text.toInt(&ok,16);
}

main.cpp

#include <QtGui/QApplication>
#include "hexspinbox.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
HexSpinBox *hexSpinBox=new HexSpinBox;
hexSpinBox->sizeHint();
hexSpinBox->show();
return app.exec();
}

image

PS:庆祝空间人气突破 25000

这几次主要练习 Qt Designer 的设计,所以就做了对话框,没有去做具体的实现,以后有空再写吧….哇哈哈

主要代码如下:

sortdialog.h

#ifndef SORTDAILOG_H
#define SORTDAILOG_H
#include <QtGui/QDialog>
#include "ui_sortdailog.h"
namespace Ui
{
class sortdailogClass;
}
class sortdailog : public QDialog
{
Q_OBJECT
public:
sortdailog(QWidget *parent = 0);
~sortdailog();
void setColumnRange(QChar first,QChar last); //用来设置列的范围
private:
Ui::sortdailogClass *ui;
};
#endif // SORTDAILOG_H

sortdialog.cpp

#include "sortdailog.h"
#include<QtGui>

sortdailog::sortdailog(QWidget *parent)
: QDialog(parent)
{
ui->setupUi(this);
ui->secondaryGroupBox->hide(); //设置为隐藏
ui->tertiaryGroupBox->hide(); //设置为隐藏
this->layout()->setSizeConstraint(QLayout::SetFixedSize); //将此层设置为适合大小
setColumnRange('A','Z'); //设置默认范围*/
}
sortdailog::~sortdailog()
{
delete ui;
}
void sortdailog::setColumnRange(QChar first,QChar last)
{
//清除原有数据
ui->primaryComboBox->clear();
ui->secondaryComboBox->clear();
ui->tertiaryComboBox->clear();
ui->secondaryComboBox->addItem(tr("None"));
ui->tertiaryComboBox->addItem(tr("None"));
ui->primaryComboBox->setMinimumSize(ui->secondaryComboBox->sizeHint()); //设置理想大小
QChar ch=first;
while(ch<=last)
{
ui->primaryComboBox->addItem(QString(ch)); //QString(ch)因为tr()只能接受字符串类型
ui->secondaryComboBox->addItem(QString(ch));
ui->tertiaryComboBox->addItem(QString(ch));
ch=ch.unicode()+1;
}
}

main.cpp

#include <QtGui/QApplication>
#include "sortdailog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
sortdailog *dialog=new sortdailog;
dialog->setColumnRange('C','H');
dialog->show();
return a.exec();
}

先用 Qt Designer 设计,窗体的基本框架,然后进行编译 ,以下是相关代码: gotocell.h

#ifndef GOTOCELL_H
#define GOTOCELL_H
#include <QtGui/QDialog>
#include "ui_gotocell.h"
namespace Ui
{
class goToCellClass;
}
class goToCell : public QDialog,public Ui::goToCellClass // public Ui::goToCellClass这句话要再Qt Designer设计完后加上不然会编译错误
{
Q_OBJECT
public:
goToCell(QWidget *parent = 0);
~goToCell();
private slots:
void on_lineEdit_textChanged();
private:
Ui::goToCellClass *ui;
};
#endif // GOTOCELL_H

gotocell.cpp

#include<QtGui>
#include "gotocell.h"
#include "ui_gotocell.h"
goToCell::goToCell(QWidget *parent)
: QDialog(parent), ui(new Ui::goToCellClass)
{
ui->setupUi(this);
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); //[A-Za-z][1-9][0-9]{0,2}的意思是:允许输入大小写字母,
//后面跟着一个范围为1-9的数字,后面再跟着0个,1个或者2个的0-9的数字
lineEdit->setValidator(new QRegExpValidator(regExp,this)); // 添加一个验证器用来验证lineEdit里面的字符串
connect(okButton,SIGNAL(accepted()),this,SLOT(accept()));
connect(cancelButton,SIGNAL(rejected()),this,SLOT(reject()));
}
goToCell::~goToCell()
{
delete ui;
}
void goToCell::on_lineEdit_textChanged()
{
okButton->setEnabled(lineEdit->hasAcceptableInput());
}

main.cpp

#include <QtGui/QApplication>
#include "gotocell.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
goToCell *dialog=new goToCell;
dialog->show();
return app.exec();
}

主要学习简单的 Wdiget 的添加问题…

main.cpp

#include <QtGui/QApplication>
#include<QSpinBox>
#include<QSlider>
#include<QHBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//创建一个小窗体部件
QWidget *widget=new QWidget;
widget->setWindowTitle("input your age");
//创建一个QSpinBox,并设置范围0-130
QSpinBox *spinBox=new QSpinBox;
spinBox->setRange(0,130);
//创建一个QSlider,并设置范围0-130
QSlider *slider=new QSlider(Qt::Horizontal);
slider->setRange(0,130);
//设置信号和槽
QObject::connect(spinBox,SIGNAL(vauleChanged(int)),slider,SLOT(setValue(int)));
QObject::connect(slider,SIGNAL(valueChanged(int)),spinBox,SLOT(setValue(int)));
//初始值
spinBox->setValue(0);
//布局设置
QHBoxLayout *layout=new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
widget->setLayout(layout);
widget->show();
return a.exec();
}

运行结果

image

PS:居然 connect 中 sender 的函数打错了还能用….好囧啊

创建一个 FindDialog,功能还没有添加…以后再搞吧

代码:

findDialog.h

#ifndef FINDDIALOG_H
#define FINDDIALOG_H
#include <QtGui/QDialog>
#include<QCheckBox>
#include<QLabel>
#include<QLineEdit>
#include<QPushButton>
namespace Ui
{
class FindDialogClass;
}
class FindDialog : public QDialog
{
Q_OBJECT
public:
FindDialog(QWidget *parent = 0);
~FindDialog();
signals:
void findNext(const QString &amp;str,Qt::CaseSensitivity cs); //不要写成 Qt::CaseSensitive,Qt::CaseSensitivity是一个类型
void findPrev(const QString &amp;str,Qt::CaseSensitivity cs);
private slots:
void findClicked();
void enableFindButton(const QString &amp;text);
private:
Ui::FindDialogClass *ui;
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
};
#endif // FINDDIALOG_H

findDialog.cpp

#include<QtGui>
#include<QHBoxLayout>
#include "finddialog.h"
#include "ui_finddialog.h"
FindDialog::FindDialog(QWidget *parent)
: QDialog(parent), ui(new Ui::FindDialogClass)
{
ui->setupUi(this);
//对部件进行定义
label=new QLabel(tr("&amp;Input the word you want to find"));
lineEdit=new QLineEdit();
label->setBuddy(lineEdit); //setBuddy 当按下快捷键时,转换到lineEdit
caseCheckBox=new QCheckBox(tr("Match &amp;Case"));
backwardCheckBox=new QCheckBox(tr("Search &amp;backward"));
findButton=new QPushButton(tr("Find"));
closeButton=new QPushButton(tr("Close"));
//添加信号连接
connect(lineEdit,SIGNAL(textChanged(const QString &amp;)),this,SLOT(enableFindButton(const QString &amp;)));
connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
//布局控制
QHBoxLayout *topLeftLayout=new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
QVBoxLayout *leftLayout=new QVBoxLayout;
leftLayout->addLayout(topLeftLayout); //添加topLeftLayout层到leftLayout层上
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);
QVBoxLayout *rightLayout=new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch(); //添加延展
//设置mianLayout将leftLayout和rightLayout添加到上面
QHBoxLayout *mainLayout=new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
this->setLayout(mainLayout);
this->setWindowTitle(tr("Find"));
this->setFixedHeight(sizeHint().height());
}
FindDialog::~FindDialog()
{
delete ui;
}
void FindDialog::findClicked()
{
QString text=lineEdit->text();
Qt::CaseSensitivity cs=caseCheckBox->isChecked()?Qt::CaseSensitive : Qt::CaseInsensitive;
if(backwardCheckBox->isChecked())
emit findPrev(text,cs); //emit用于发射信号
else emit findNext(text,cs);
}
void FindDialog::enableFindButton(const QString &amp;text)
{
findButton->setEnabled(!text.isEmpty());
}

main.cpp

#include <QtGui/QApplication>
#include "finddialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FindDialog *findDialog=new FindDialog;
findDialog->show();
return app.exec();
}

运行结果:

image

PS 编译过程出现这个错误: :-1: error: collect2: ld returned 1 exit status ,但是当我程序写完的时候问题就解决了 ….orz,顺便说下,QtCreator 的补全功能还是很不错的….1.0 果然比 0.9 好太多了….赞一个