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? :mad:
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
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().
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?
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
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.
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 :confused:
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.
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) :confused:
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?
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.
Code:
{
int X = event->x();
int Y = event->y();
if( X > 0 && X < 160)
{
if( Y > 0 && Y < 80)
{
TWButton
->setPalette
( QColor( 255,
255,
255,
255));
textLabel->setText( twString);
}
else
TWButton
->setPalette
( QColor( 0,
170,
255,
255));
etc.
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.
Re: Make different regions of QLabel act differently, like an image map
Finally, someone who answers not to just get their post count up :D. Brilliant idea, thanks a lot :)
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? :confused:
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
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.