Results 1 to 14 of 14

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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?

  2. #2
    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

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 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

  4. #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

    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

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 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

  6. #6
    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)

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 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

  8. #8
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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.

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

    codeslicer (17th February 2008)

  10. #9
    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

  11. #10
    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

  12. #11
    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?

  13. #12
    Join Date
    Jan 2008
    Posts
    31
    Thanks
    1
    Thanked 2 Times in 2 Posts
    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
  •  
Qt is a trademark of The Qt Company.