Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. No pen cursor n Qt library
Forum Updated to NodeBB v4.3 + New Features

No pen cursor n Qt library

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 719 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oneeyeman1
    wrote on last edited by
    #1

    Hi,
    The documentation at https://doc.qt.io/qt-6/qt.html#CursorShape-enum does not display Pen Shaped cursor as a possible type.

    I'm working with X11/Linux and want to see if there is a possibilty of getting a pen shaped cursor (for drawing program).

    Thank you.

    P.S.: This is surprising as it is a fairly often used cursor shape...

    W 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The most simple would be for you to provide that cursor in your application.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • O Offline
        O Offline
        oneeyeman1
        wrote on last edited by
        #3

        Hi,
        Are you saying that all those painting apps provide pen shaped cursor?
        And there is nothing like it inside X11/Wayland?

        Thank you.

        Christian EhrlicherC 1 Reply Last reply
        0
        • O oneeyeman1

          Hi,
          Are you saying that all those painting apps provide pen shaped cursor?
          And there is nothing like it inside X11/Wayland?

          Thank you.

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @oneeyeman1 said in No pen cursor n Qt library:

          Are you saying that all those painting apps provide pen shaped cursor?

          Why should the operating system provide application specific cursors? They must be provided by the application.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • O Offline
            O Offline
            oneeyeman1
            wrote on last edited by
            #5

            Hi,
            Im not asking for the OS - I'm asking for the library to provide a well known cursor for re'use on different apps.

            Moreover, most developers are not UI designer and create some bitmap/png/upgrade is a nightmare...

            Thank you.

            Christian EhrlicherC 1 Reply Last reply
            0
            • O oneeyeman1

              Hi,
              Im not asking for the OS - I'm asking for the library to provide a well known cursor for re'use on different apps.

              Moreover, most developers are not UI designer and create some bitmap/png/upgrade is a nightmare...

              Thank you.

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @oneeyeman1 said in No pen cursor n Qt library:

              I'm asking for the library to provide a well known cursor for re'use on different apps.

              What is 'well known cursor'? Who defines it?
              Qt is providing an abstraction to access the os cursors, nothing more and tbh I don't see why it should provide a set of some cursors for specific applications.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • O Offline
                O Offline
                oneeyeman1
                wrote on last edited by
                #7

                Hi,
                Then why do you provide all those cursor annum referenced at the link I gave in the OP?

                Now if you open for example Paint on Windows, it will start with the cursor represented as a pen. This pen is defined somewhere in the public Windows C/C++/Java/.NET/whatever API as well as the icon somewhere on the system.
                There is also an "I-beam: cursor with the same thing except that for some reason Qt provides enum definition for the "I-beam".

                Is there a possibility to retrieve the pen cursor icon from X11/Wayland?

                Thank you.

                Christian EhrlicherC 1 Reply Last reply
                0
                • O oneeyeman1

                  Hi,
                  Then why do you provide all those cursor annum referenced at the link I gave in the OP?

                  Now if you open for example Paint on Windows, it will start with the cursor represented as a pen. This pen is defined somewhere in the public Windows C/C++/Java/.NET/whatever API as well as the icon somewhere on the system.
                  There is also an "I-beam: cursor with the same thing except that for some reason Qt provides enum definition for the "I-beam".

                  Is there a possibility to retrieve the pen cursor icon from X11/Wayland?

                  Thank you.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by Christian Ehrlicher
                  #8

                  Is there a possibility to retrieve the pen cursor icon from X11/Wayland?

                  What pen cursor are you referring here? X11 and wayland are window managers, they don't provide cursors.

                  Now if you open for example Paint on Windows, it will start with the cursor represented as a pen.

                  Here are the cursors provided directly by windows: https://learn.microsoft.com/de-de/windows/win32/menurc/about-cursors

                  As you can see there is no pen - Paint is a standalone program which ships it's own cursors.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  Pl45m4P 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    Is there a possibility to retrieve the pen cursor icon from X11/Wayland?

                    What pen cursor are you referring here? X11 and wayland are window managers, they don't provide cursors.

                    Now if you open for example Paint on Windows, it will start with the cursor represented as a pen.

                    Here are the cursors provided directly by windows: https://learn.microsoft.com/de-de/windows/win32/menurc/about-cursors

                    As you can see there is no pen - Paint is a standalone program which ships it's own cursors.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @Christian-Ehrlicher said in No pen cursor n Qt library:

                    As you can see there is no pen

                    Actually there is a pen icon (MAKEINTRESOURCE(32631)) defined in WinUser.h, but in the second table and it says that these icons don't have a specifier because they are not in use or not standard anymore.


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    1
                    • O Offline
                      O Offline
                      oneeyeman1
                      wrote on last edited by
                      #10

                      Hi,
                      As you can see from the OP, I don't work in windows with Qt - I use Linux.
                      So any chance I find this icon/pixmap on Linux somewhere?

                      Thank you.

                      Pl45m4P 1 Reply Last reply
                      0
                      • O oneeyeman1

                        Hi,
                        As you can see from the OP, I don't work in windows with Qt - I use Linux.
                        So any chance I find this icon/pixmap on Linux somewhere?

                        Thank you.

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by
                        #11

                        @oneeyeman1 said in No pen cursor n Qt library:

                        So any chance I find this icon/pixmap on Linux somewhere?

                        If you don't check you will never know :)
                        Go where the icons are stored for your Linux distro...
                        As there was said before... if there isn't such standard icon, you have to create your own cursor set and ship it with your app... like most painting tools, games and other programs do


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        1 Reply Last reply
                        0
                        • O oneeyeman1

                          Hi,
                          The documentation at https://doc.qt.io/qt-6/qt.html#CursorShape-enum does not display Pen Shaped cursor as a possible type.

                          I'm working with X11/Linux and want to see if there is a possibilty of getting a pen shaped cursor (for drawing program).

                          Thank you.

                          P.S.: This is surprising as it is a fairly often used cursor shape...

                          W Offline
                          W Offline
                          wrosecrans
                          wrote on last edited by
                          #12

                          @oneeyeman1 When I want a "familiar" but not universal icon for my application, I usually start by checking to see if there's an emoji that will work. You can render that from text using your favorite font with that character and set it as a custom cursor.

                          Here's a somewhat janky utility function I have that you might find useful as a starting point. I use Font Awesome as my default font for UI symbol stuff and bundle it with the app, but you can specify whatever font when doing this sort of thing. It includes stuff like paintbrush icons, and a zillion other things that you might want https://fontawesome.com/icons/paintbrush?f=classic&s=solid

                          If you are using standard emoji, you can even type them directly into your source code these days and do stuff like

                          auto myBrushIcon = to_Icon("🖌")
                          
                          
                          QIcon to_Icon(const std::string text, int size=64, std::string font="Font Awesome 5 Free", QColor background = QColor(255, 255, 255, 128));
                           ///
                          
                          QIcon to_Icon(const std::string text, int size, std::string font, QColor background)
                          {
                              QPixmap pm(size, size);
                              pm.fill(Qt::transparent);
                          
                              QPainter p(&pm);
                              int margins = 0;
                              p.fillRect(margins, margins, size-margins, size-margins, background);
                          
                              QFont icon_font;
                              if (font != "") {
                                  icon_font.setFamily(font.c_str());
                              }
                          
                              icon_font.setPixelSize(size*.75);
                              icon_font.setWeight(0);
                              p.setFont(icon_font);
                          
                              QFontMetrics metrics(icon_font, &pm);
                              auto y = metrics.height();  // descent();
                              auto x = metrics.width(QString::fromStdString(text));
                              x = metrics.horizontalAdvance(QString::fromStdString(text));
                              auto offset = (size-x) / 2; // size - y - 1
                              p.drawText(offset, y, QString::fromStdString(text));
                          
                              p.end();
                              return QIcon(pm);
                          }
                          
                          1 Reply Last reply
                          0
                          • AtesCompA Offline
                            AtesCompA Offline
                            AtesComp
                            wrote on last edited by
                            #13

                            For Linux, the standard set of cursors for cursor themes are documented in /usr/include/X11/cursorfont.h. These are the 'well known' cursors under Linux OSes and have been for decades (notice the "Copyright 1987, 1998 The Open Group").

                            For documentation, see:
                            For KDE (in particular Creating the symlinks)
                            For General X11

                            Note the XC_pencil entry. Yes, there are a lot of silly ones (XC_bogosity anyone).

                            I'm almost sure the Qt devs know this. They had to have done some kind of background research on this to get the Qt::CursorShape enums to map to the system's cursor theme.

                            There...homework done!

                            Extra Credit:

                            All of the entries are related to so-called cursor state. The cursor images map to one or more states . A cursor theme does not require all cursor state be mapped by cursor images, so some cursors may be missing from a theme. However, a "good" theme should have an Inherits= key-value in the [Icon Theme] section of its the index.theme file so that it has a chance to complete the entire theme with some kind of cursor image for each state.

                            What does Qt do when a system cursor is not present in the current theme?

                            In any case, the best practice is to test for these cursors by the given Qt::CursorShape enums and, if not found, provide your own by using QCursor(const QPixmap...) or QCursor(const QBitmap...). Admittedly, the Qt::CursorShape enums should likely expand to cover all standard cursor icons provided by the OS. The QCursor(Qt::CursorShape shape) and void QCursor::setShape(Qt::CursorShape shape) method should likely throw some exception when a cursor is not actually found in the system's current theme. Or, to make things a bit nicer, change setShape() to return a boolean value.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved