qt学习笔记(四) qt编程时遇到的问题的总结
来源:互联网 发布:js身份证格式验证 编辑:程序博客网 时间:2024/05/16 15:23
1、设置qt widget全屏显示
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- MainWindow w;
- //w.show();
- w.showFullScreen();
- return a.exec();
- }
int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; //w.show(); w.showFullScreen(); return a.exec();}
2、获取屏幕分辨率
- #include <QDesktopWidget>
- #Include <QApplication>
- void MainWindow::GetScreenInfo()
- {
- QDesktopWidget* desktopWidget = QApplication::desktop();
- //获取可用桌面大小
- //QRect deskRect = desktopWidget->availableGeometry();
- //获取设备屏幕大小
- QRect screenRect = desktopWidget->screenGeometry();
- sceenSizeX = screenRect.width();
- sceenSizeY = screenRect.height();
- //获取系统设置的屏幕个数(屏幕拷贝方式该值为1)
- //g_nScreenCount = desktopWidget->screenCount();
- }
#include <QDesktopWidget>#Include <QApplication>void MainWindow::GetScreenInfo(){ QDesktopWidget* desktopWidget = QApplication::desktop(); //获取可用桌面大小 //QRect deskRect = desktopWidget->availableGeometry(); //获取设备屏幕大小 QRect screenRect = desktopWidget->screenGeometry(); sceenSizeX = screenRect.width(); sceenSizeY = screenRect.height(); //获取系统设置的屏幕个数(屏幕拷贝方式该值为1) //g_nScreenCount = desktopWidget->screenCount();}
3、QGraphicsView添加背景图片:1
- view = new QGraphicsView;
- scene = new QGraphicsScene(0,0,800,480);
- QPixmap pixmap(":/gear.png");
- scene->addPixmap(pixmap);
- view->setScene(scene);
view = new QGraphicsView; scene = new QGraphicsScene(0,0,800,480); QPixmap pixmap(":/gear.png"); scene->addPixmap(pixmap); view->setScene(scene);
3、QGraphicsView添加背景图片:2
- view->setBackgroundBrush(QImage(":/gear.png"));
view->setBackgroundBrush(QImage(":/gear.png"));前提是将gear.png加入到资源中
4、设置无边框(标题栏)的应用程序
- QApplication a(argc, argv);
- MainWindow w;
- w.setWindowOpacity(1);
- w.setWindowFlags(Qt::FramelessWindowHint);
- w.setAttribute(Qt::WA_TranslucentBackground);
- w.show();
QApplication a(argc, argv); MainWindow w; w.setWindowOpacity(1); w.setWindowFlags(Qt::FramelessWindowHint); w.setAttribute(Qt::WA_TranslucentBackground); w.show();
5 、QGraphicsPixmapItem,显示图片Item
- scene = new QGraphicsScene(0,0,800,480);
- QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(QPixmap(":/gear.png"));
- pixmapItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
- scene->addItem(pixmapItem);
scene = new QGraphicsScene(0,0,800,480); QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(QPixmap(":/gear.png")); pixmapItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); scene->addItem(pixmapItem);
6 Q_OBJECT 问题
- class NodeUI : public QGraphicsPixmapItem
- {
- Q_OBJECT
- ...
- }
class NodeUI : public QGraphicsPixmapItem{ Q_OBJECT...}编译不通过
- class NodeUI : public QGraphicsPixmapItem ,public QObject
- {
- Q_OBJECT
- ...
- }
class NodeUI : public QGraphicsPixmapItem ,public QObject{ Q_OBJECT...}依然不通过
- class NodeUI : public QObject,public QGraphicsPixmapItem
- {
- Q_OBJECT
- ...
- }
class NodeUI : public QObject,public QGraphicsPixmapItem{ Q_OBJECT...}编译通过!
7 ,编译出错:error: passing 'const QPointF' as 'this' argument of 'QPointF& QPointF::operator=(const QPointF&)' discards qualifiers
- NodeUI *MainWindow::selectedNodeUI() const
- {
- QList<QGraphicsItem *> items = scene->selectedItems();
- if (items.count() == 1) {
- mmyPos = items.first()->pos();
- //QPointF myPos = pos;
- //mmyPos = pos.toPoint();
- //mmyPos.setX(x);
- //mmyPos.setY(y);
- //mmyPos = QPoint(x,y);
- //qDebug()<<"items.x:"<<nodePos.x()<<"items.y:"<<nodePos.y();
- return dynamic_cast<NodeUI *>(items.first());
- } else {
- return 0;
- }
- }
NodeUI *MainWindow::selectedNodeUI() const{ QList<QGraphicsItem *> items = scene->selectedItems(); if (items.count() == 1) { mmyPos = items.first()->pos(); //QPointF myPos = pos; //mmyPos = pos.toPoint(); //mmyPos.setX(x); //mmyPos.setY(y); //mmyPos = QPoint(x,y); //qDebug()<<"items.x:"<<nodePos.x()<<"items.y:"<<nodePos.y(); return dynamic_cast<NodeUI *>(items.first()); } else { return 0; }}修改为如下,问题解决;
- NodeUI *MainWindow::selectedNodeUI()
- {
- QList<QGraphicsItem *> items = scene->selectedItems();
- if (items.count() == 1) {
- mmyPos = items.first()->pos();
- //QPointF myPos = pos;
- //mmyPos = pos.toPoint();
- //mmyPos.setX(x);
- //mmyPos.setY(y);
- //mmyPos = QPoint(x,y);
- //qDebug()<<"items.x:"<<nodePos.x()<<"items.y:"<<nodePos.y();
- return dynamic_cast<NodeUI *>(items.first());
- } else {
- return 0;
- }
- }
NodeUI *MainWindow::selectedNodeUI(){ QList<QGraphicsItem *> items = scene->selectedItems(); if (items.count() == 1) { mmyPos = items.first()->pos(); //QPointF myPos = pos; //mmyPos = pos.toPoint(); //mmyPos.setX(x); //mmyPos.setY(y); //mmyPos = QPoint(x,y); //qDebug()<<"items.x:"<<nodePos.x()<<"items.y:"<<nodePos.y(); return dynamic_cast<NodeUI *>(items.first()); } else { return 0; }}
8,QMap遍历问题
QMap插入时的顺序和最后得到的QMap遍历顺序可能是不通的,QMap所谓的有序是按照key内部自动升序,在不同的电脑上,顺序都可能不同。
对顺序有要求时,不可以用QMap,QHash就更不用说了。
转自:http://blog.csdn.net/ghostyu/article/details/7002178- qt学习笔记(四) qt编程时遇到的问题的总结
- qt学习笔记(四) qt编程时遇到的问题的总结
- qt学习笔记(四) qt编程时遇到的问题的总结
- QT编程中遇到的问题总结
- QT编程遇到的问题
- QT学习遇到的问题(1)
- QT学习遇到的问题(2)
- qt编程遇到的小问题
- Qt网络编程遇到的小问题
- Qt中遇到的一些问题总结
- 用QT编程时遇到的错误总结
- 用QT编程时遇到的错误总结
- 【Qt】遇到的问题
- QT 遇到的问题
- Qt遇到的问题
- qt编程修改windows登陆界面时遇到的问题
- Qt学习中遇到的问题
- QT学习中遇到的问题!!!
- qt学习笔记(五)QGraphicsPixmapItem与QGraphicsScene的编程实例 图标拖动渐变效果
- 更换Winform界面的皮肤
- 常用转移指令整理
- openGL CG4 - Lighting + Texture
- AlertDialog
- qt学习笔记(四) qt编程时遇到的问题的总结
- 16位汇编寄存器和寻址方式总结
- Oracle11g导入导出
- qt学习笔记(三) QString char int之间的转换
- 今天你买到票了吗?——从铁道部12306.cn网站漫谈电子商务网站的“海量事务高速处理”系统
- servlet
- Android编程之横屏竖屏切换及状态保存
- qt学习笔记(二) QString
- 保存和恢复activity的状态数据