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. Cannot disable QGraphicsSimpleText antialiasing with Qt5.x

Cannot disable QGraphicsSimpleText antialiasing with Qt5.x

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsviewqt 5.6.0qt 5.4.2qt 4.8.6
4 Posts 2 Posters 2.2k Views
  • 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.
  • JohanSoloJ Offline
    JohanSoloJ Offline
    JohanSolo
    wrote on last edited by
    #1

    Hi all,

    I'm trying to implement a widget which should:

    1. display a picture from raw pgm-like data;
    2. superimpose zones of interest with a reticle-like object and a small text.

    The pictures are roughly full HD, and the number of zones of interest usually varies between 3 and 16.

    After looking out for information, I somehow decided to go for the Graphics View Framework: I draw the picture using a QGraphicsPixmapItem (updated regularly), the zones of interest use a custom QGraphicsItem subclass and the text uses QGraphicsSimpleTextItem instances those are updated at the same time as the picture. In order to avoid to blow up the memory, I first update the position / texts of pre-existing items instead of creating new ones and I only update the pixmap.

    I've had OpenGL performance issues with some hardware, this is why I don't use OpenGL to display the view. The default implementation won't use OpenGL and let the CPU perform the rendering.

    I have an option to disable the antialiasing of the view (triggered by right-clicking on the widget), the code which toggles on / off the antialiasing looks like this:

    void PictureDisplay::toggleSmoothing()
    {
        QPainter::RenderHints hints( renderHints() );
        hints ^= QPainter::Antialiasing;
        hints ^= QPainter::TextAntialiasing;
        hints ^= QPainter::SmoothPixmapTransform;
        hints ^= QPainter::HighQualityAntialiasing;
        setRenderHints( hints );
        QFont font( "Arial", 18 );
        if ( ( hints & QPainter::HighQualityAntialiasing ) != 0 )
        {
            font.setStyleStrategy( QFont::PreferAntialias );
            foreach ( QGraphicsSimpleTextItem* item, OverlaidTexts )
            {
                item->setFont( font );
            }
            PixmapItem->setTransformationMode( Qt::SmoothTransformation );
        }
        else
        {
            font.setStyleStrategy( QFont::NoAntialias );
            foreach ( QGraphicsSimpleTextItem* item, OverlaidTexts )
            {
                item->setFont( font );
            }
            PixmapItem->setTransformationMode( Qt::FastTransformation );
        }
    }
    

    I've tested this code with Qt 5.6.0 64bits on Windows 8.1 using MSVC 2013, Qt 5.4.2 64bits on Mageia 5 using both gcc 4.9 and clang 3.5, Qt 4.8.6 64bits on Mageia 5 using gcc 4.9.
    Now, here's the catch:

    • the Windows Qt 5.6 version does not disable text antialiasing, unless I use the OpenGL viewport;
    • the Linux Qt 5.4 version does not disable text antialiasing (and I have no OpenGL output, i.e. blank widget, but never mind);
    • the Linux Qt 4.8 does disable text antialiasing (and I have no OpenGL output, i.e. blank widget, but never mind).

    I've already spent some time reading the documentation (for both 4.8 and 5.6) with no luck, everybody seems to agree that font.setStyleStrategy( QFont::NoAntialias ); should disable the text antialiasing for whatever Qt version.

    Can someone show me where I did wrong?

    Thanks in advance,

    johan

    `They did not know it was impossible, so they did it.'
    -- Mark Twain

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

      Hi,

      The backends between Qt 4 and 5 have changed so you might have unearthed something. I'd recommend taking a look at the bug report system to see if it's something known.

      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
      0
      • JohanSoloJ Offline
        JohanSoloJ Offline
        JohanSolo
        wrote on last edited by
        #3

        Hi Samuel,

        thank you for the answer. I've already give a quick look at the bug tracker and didn't find any related bug. I'll give another try an file a new bug if needed.

        Merci!

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          For the recored, filed QTBUG-53845

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          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