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. QLabel Opacity Register Event

QLabel Opacity Register Event

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 396 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.
  • N Offline
    N Offline
    nanamo
    wrote on last edited by
    #1

    Hello Folks
    Maybe you can help.
    I have a QLabel with QPixmap (code below) so that when you click it switches between on and off icons.
    This works perfect.
    However, the only area of the QLabel that registers a touch or mouse-click is the non-transparent areas of the QPixmap which is a PNG image.
    It becomes difficult to press as you have to hit the non-opaque sections of the PNG.
    The issue is this line,if i remove it the click registers on the entire 200X200 pixel QLabel but then I lose the transparency effect

    icon->setAttribute(Qt::WA_TranslucentBackground, true);
    

    Any clues as to how i make the entire 200x200 Qlabel clickable even the transparent bits?

    mainArea::mainArea(QWidget *parent) :QLabel(parent)
    icon->setObjectName(name);
    icon->setGeometry(QRect(x, y, w, h));
    icon->setOnPixmap(QPixmap(imgOnInd_dm));
    icon->setOffPixmap(QPixmap(imgOffInd_dm));
    icon->setAttribute(Qt::WA_TranslucentBackground, true);
    icon->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    icon->setVisible(vis);
    QObject::connect(icon, SIGNAL(clicked()), this, SLOT(btnClicked()));
    
    JonBJ 1 Reply Last reply
    0
    • N nanamo

      Hello Folks
      Maybe you can help.
      I have a QLabel with QPixmap (code below) so that when you click it switches between on and off icons.
      This works perfect.
      However, the only area of the QLabel that registers a touch or mouse-click is the non-transparent areas of the QPixmap which is a PNG image.
      It becomes difficult to press as you have to hit the non-opaque sections of the PNG.
      The issue is this line,if i remove it the click registers on the entire 200X200 pixel QLabel but then I lose the transparency effect

      icon->setAttribute(Qt::WA_TranslucentBackground, true);
      

      Any clues as to how i make the entire 200x200 Qlabel clickable even the transparent bits?

      mainArea::mainArea(QWidget *parent) :QLabel(parent)
      icon->setObjectName(name);
      icon->setGeometry(QRect(x, y, w, h));
      icon->setOnPixmap(QPixmap(imgOnInd_dm));
      icon->setOffPixmap(QPixmap(imgOffInd_dm));
      icon->setAttribute(Qt::WA_TranslucentBackground, true);
      icon->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
      icon->setVisible(vis);
      QObject::connect(icon, SIGNAL(clicked()), this, SLOT(btnClicked()));
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @nanamo
      There may be a better answer, but:

      Why choose a QLabel for clickability? This can be done via a QPushButton, which more naturally supports clicking. Does https://stackoverflow.com/questions/35442678/pyqt-button-click-area-non-rectangular-area help?

      Alternatively I come across https://wiki.python.org/moin/PyQt/Making non-clickable widgets clickable (Qt4, but hopefully still applicable) which uses eventFilter() and detecting mouse release in object rectangle.

      N 1 Reply Last reply
      0
      • JonBJ JonB

        @nanamo
        There may be a better answer, but:

        Why choose a QLabel for clickability? This can be done via a QPushButton, which more naturally supports clicking. Does https://stackoverflow.com/questions/35442678/pyqt-button-click-area-non-rectangular-area help?

        Alternatively I come across https://wiki.python.org/moin/PyQt/Making non-clickable widgets clickable (Qt4, but hopefully still applicable) which uses eventFilter() and detecting mouse release in object rectangle.

        N Offline
        N Offline
        nanamo
        wrote on last edited by
        #3

        @JonB Thanks Jon
        QPushButton not a goer as is would be too much of an upheaval at this stage considering the work done to this point.
        I will look at your eventfilter suggestion.

        I thought the answer would be more straightforward than this but Ive been looking for a few days now..head wrecked.

        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