Results 1 to 14 of 14

Thread: Make different regions of QLabel act differently, like an image map

  1. #1
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Make different regions of QLabel act differently, like an image map

    So this is the scenario:

    I am making a custom QWidget dialog with an irregular shape. Since I have ommited the system's native window decorations, I need to reimplement that myself. At the top, I have a long image with different button "markers". I want the image to "change" depending on where the mouse is, and to also perform different actions depending on which part of the QLabel image was pressed. For example, if I have an image with 3 buttons drawn on it, I want each of those buttons to be brighter when it is hovered, and when one of the buttons is pressed, say the minimize button, the application would be minimized. Is this possible, say using subclassing QLabel, or is this out of reach of Qt?

    Thanks in advance for any help, this must be possible somehow... Also, do I have to reimplement QLabel in its own class with the enterEvent() to use it, or can I use it inside my main widget's class?

    So again, thanks in advance ~codeslicer

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Make different regions of QLabel act differently, like an image map

    It should be possible. Take look at xxxEvent() methods of QWidget class (and don't forget about QWidget::mouseTracking property). You can also use event filters --- see QObject::installEventFilter().

  3. The following user says thank you to jacek for this useful post:

    codeslicer (15th February 2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Re: Make different regions of QLabel act differently, like an image map

    So I have to make my own class? Or reimplement the QLabel class and add event handlers?

  5. #4
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Make different regions of QLabel act differently, like an image map

    Well... I know this sounds nooby, but how would I use the installEventFilter()? I read the Key-press-eater, but how does that work? Do I have to make a seperate eventFilter class? And attach that to an object usign coding - not designer? THanks in advance - codeslicer

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Make different regions of QLabel act differently, like an image map

    You can use any existing QObject subclass as an event filter. It could be for example your window class which loads the designed ui.
    J-P Nurmi

  7. #6
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Make different regions of QLabel act differently, like an image map

    Ok... how would the code work for it though? And is there any way that I can integrate it into Qt Designer, or do I have to somehow place it in there using code only

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Make different regions of QLabel act differently, like an image map

    Qt Designer is a layout designer. You don't implement functionality in Qt Designer. You implement functionality by writing code.
    J-P Nurmi

  9. #8
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: Make different regions of QLabel act differently, like an image map

    Ok... but how would I do that though? I know how to arrange the form, I'll figure it out by looking at the generate header-from-uic file, but how can I make that event filter and how would I use it with a QLabel (or a subclassed QLabel)

  10. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Make different regions of QLabel act differently, like an image map

    So how do you use that form you created in Qt Designer? Are you using single or multiple inheritance approach?
    J-P Nurmi

  11. #10
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make different regions of QLabel act differently, like an image map

    I had a similar scenario with a row of PushButtons that I wanted to change color as the mouse was over them. They were implemented flat in QTDesigner with mouseTracking set true. Text in a QLabel also changed depending on the PushButton under the cursor.

    Qt Code:
    1. void Clone::mouseMoveEvent( QMouseEvent *event)
    2. {
    3. int X = event->x();
    4. int Y = event->y();
    5.  
    6. if( X > 0 && X < 160)
    7. {
    8. if( Y > 0 && Y < 80)
    9. {
    10. TWButton->setPalette( QColor( 255,255,255,255));
    11. textLabel->setText( twString);
    12. }
    13. else
    14. TWButton->setPalette( QColor( 0,170,255,255));
    15.  
    16. etc.
    To copy to clipboard, switch view to plain text mode 

    I'm sure you could accomplish the same thing with a group of QLabels merged together so they would look like a single object until changed by the cursor.

  12. The following user says thank you to GTBuilder for this useful post:

    codeslicer (17th February 2008)

  13. #11
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Make different regions of QLabel act differently, like an image map

    Finally, someone who answers not to just get their post count up . Brilliant idea, thanks a lot

  14. #12
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: Make different regions of QLabel act differently, like an image map

    Sorry jpn, didn't see your comment
    I'm using multiple-inheritance, so do I have to have several QLabels in the same place, each being transparent in all places except for where the button would be? If so, how would I switch their order from top to bottom?


    Oh, and in the code above, what would I replace Clone with, a subclass of a QLabel, or the name of my label that I want to switch?

    Thanks in advance ~codeslicer

  15. #13
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Need help please :)

    *bump* Anyone?

  16. #14
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Make different regions of QLabel act differently, like an image map

    Clone is the base widget that I populate with 4 QPushButtons, 2 QRadioButtons and 2 QLabels. The RadioButtons are invisible and superimposed on one of the pushbuttons. They are set visible after the button is clicked and set invisible again after one or the other is clicked launching a QProcess.

    Intent is to emulate an html page.

Similar Threads

  1. Set the image at the center in QLabel?
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2007, 14:07
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.