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. Providing image to icons without QLabel and ui
Qt 6.11 is out! See what's new in the release blog

Providing image to icons without QLabel and ui

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 342 Views 1 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by Swati777999
    #1

    Hi All,

    I'm new to Qt. I want to provide images to my icons without Qlabel and ui. Can someone tell me if it is possible through the combination of QIcon and QPixmap?

    The following code snippet is given in the documentation but when I tried it in my computer after including following header file, gives error [ isChecked() is undeclared identifier]

    #include <QMainWindow>
    #include <QPainter>
    #include<QPoint>
    #include <QPixmap>
    #include <QCheckBox>
    #include<QIcon>

    void MyWidget::drawIcon(QPainter *painter, QPoint pos)
    {
    QPixmap pixmap = icon.pixmap(QSize(22, 22),
    isEnabled() ? QIcon::Normal
    : QIcon::Disabled,
    isChecked() ? QIcon::On
    : QIcon::Off);
    painter->drawPixmap(pos, pixmap);
    }

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    jsulmJ 1 Reply Last reply
    0
    • Swati777999S Swati777999

      Hi All,

      I'm new to Qt. I want to provide images to my icons without Qlabel and ui. Can someone tell me if it is possible through the combination of QIcon and QPixmap?

      The following code snippet is given in the documentation but when I tried it in my computer after including following header file, gives error [ isChecked() is undeclared identifier]

      #include <QMainWindow>
      #include <QPainter>
      #include<QPoint>
      #include <QPixmap>
      #include <QCheckBox>
      #include<QIcon>

      void MyWidget::drawIcon(QPainter *painter, QPoint pos)
      {
      QPixmap pixmap = icon.pixmap(QSize(22, 22),
      isEnabled() ? QIcon::Normal
      : QIcon::Disabled,
      isChecked() ? QIcon::On
      : QIcon::Off);
      painter->drawPixmap(pos, pixmap);
      }

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Swati777999 said in Providing image to icons without QLabel and ui:

      isEnabled() ? QIcon::Normal
      : QIcon::Disabled

      Simply replace this part with either QIcon::Normal or QIcon::Disabled and see whether it works...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi,

        @Swati777999 said in Providing image to icons without QLabel and ui:

        isChecked()

        What is MyWidget's base class ?
        If it's just QWidget then it does not have a isChecked method as the error tells you.

        What exactly is your goal with MyWidget ?

        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

        • Login

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