Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quick-custom-cursor
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yuya Nishihara
quick-custom-cursor
Commits
b628c798
Commit
b628c798
authored
4 years ago
by
Yuya Nishihara
Browse files
Options
Downloads
Patches
Plain Diff
Add custom QQuickItem that changes cursor
parent
182b3f45
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
CMakeLists.txt
+3
-0
3 additions, 0 deletions
CMakeLists.txt
main.cpp
+4
-0
4 additions, 0 deletions
main.cpp
main.qml
+50
-0
50 additions, 0 deletions
main.qml
myitem.cpp
+23
-0
23 additions, 0 deletions
myitem.cpp
myitem.h
+25
-0
25 additions, 0 deletions
myitem.h
with
105 additions
and
0 deletions
CMakeLists.txt
+
3
−
0
View file @
b628c798
...
...
@@ -14,7 +14,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package
(
Qt5 COMPONENTS Core Quick REQUIRED
)
add_executable
(
quick-custom-cursor
icons.qrc
main.cpp
myitem.cpp
myitem.h
qml.qrc
)
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
4
−
0
View file @
b628c798
#include
<QGuiApplication>
#include
<QQmlApplicationEngine>
#include
<QQmlEngine>
#include
"myitem.h"
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -7,6 +9,8 @@ int main(int argc, char *argv[])
QGuiApplication
app
(
argc
,
argv
);
qmlRegisterType
<
MyItem
>
(
"MyTypes"
,
1
,
0
,
"MyItem"
);
QQmlApplicationEngine
engine
;
const
QUrl
url
(
QStringLiteral
(
"qrc:/main.qml"
));
QObject
::
connect
(
&
engine
,
&
QQmlApplicationEngine
::
objectCreated
,
...
...
This diff is collapsed.
Click to expand it.
main.qml
+
50
−
0
View file @
b628c798
import
QtQuick
2.12
import
QtQuick
.
Window
2.12
import
MyTypes
1.0
Window
{
visible
:
true
width
:
640
height
:
480
title
:
qsTr
(
"
Hello World
"
)
Column
{
anchors.fill
:
parent
Item
{
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
height
:
parent
.
height
/
3
Rectangle
{
anchors.fill
:
parent
color
:
"
#ccc
"
}
Text
{
anchors.centerIn
:
parent
text
:
"
default
"
}
}
MyItem
{
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
height
:
parent
.
height
/
3
cursorSource
:
"
icons/emacs.png
"
Rectangle
{
anchors.fill
:
parent
color
:
"
#eee
"
}
Text
{
anchors.centerIn
:
parent
text
:
"
Emacs
"
}
}
MyItem
{
anchors.left
:
parent
.
left
anchors.right
:
parent
.
right
height
:
parent
.
height
/
3
cursorSource
:
"
icons/gnome.png
"
Rectangle
{
anchors.fill
:
parent
color
:
"
#ccc
"
}
Text
{
anchors.centerIn
:
parent
text
:
"
Gnome
"
}
}
}
}
This diff is collapsed.
Click to expand it.
myitem.cpp
0 → 100644
+
23
−
0
View file @
b628c798
#include
<QCursor>
#include
<QPixmap>
#include
<QQmlFile>
#include
"myitem.h"
MyItem
::
MyItem
(
QQuickItem
*
parent
)
:
QQuickItem
(
parent
)
{
}
QUrl
MyItem
::
cursorSource
()
const
{
return
cursorSource_
;
}
void
MyItem
::
setCursorSource
(
const
QUrl
&
source
)
{
if
(
cursorSource_
==
source
)
return
;
QPixmap
pix
(
QQmlFile
::
urlToLocalFileOrQrc
(
source
));
setCursor
(
QCursor
(
pix
));
emit
cursorSourceChanged
(
source
);
}
This diff is collapsed.
Click to expand it.
myitem.h
0 → 100644
+
25
−
0
View file @
b628c798
#ifndef MYITEM_H
#define MYITEM_H
#include
<QQuickItem>
#include
<QUrl>
class
MyItem
:
public
QQuickItem
{
Q_OBJECT
Q_PROPERTY
(
QUrl
cursorSource
READ
cursorSource
WRITE
setCursorSource
NOTIFY
cursorSourceChanged
)
public:
explicit
MyItem
(
QQuickItem
*
parent
=
nullptr
);
QUrl
cursorSource
()
const
;
void
setCursorSource
(
const
QUrl
&
source
);
signals:
void
cursorSourceChanged
(
const
QUrl
&
source
);
private:
QUrl
cursorSource_
;
};
#endif // MYITEM_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment