1、设置qt widget全屏显示
- 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();
- }
3、QGraphicsView添加背景图片:1
- 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"));
4、设置无边框(标题栏)的应用程序
- 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);
6 Q_OBJECT 问题
- class NodeUI : public QGraphicsPixmapItem
- {
- Q_OBJECT
- ...
- }
- class NodeUI : public QGraphicsPixmapItem ,public QObject
- {
- 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()
- {
- 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;
- }
- }