Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, January 2008
QLabel Selection Box Issue


Message 1 in thread

Hi guys,

I am facing some cosmetic issues with QLabels used as
hyperlinks. I have a form with a couple of links
(QLabels) and each of the link opens up a modal dialog
box. After closing the modal dialog box, the link
remains "selected". If somebody clicks all the links,
all of them will remain selected as long as the window
remains open. Please see attached screenshot.

Is there a way to remove this behavior (e.g. to clear
this selection box around the label after click or do
something so that it never gets the selection box at
all when clicked, but respond to the click) ?

Thanks,
Danny


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

image/pjpeg


Message 2 in thread

Danny Sporea wrote:
> Hi guys,
> 
> I am facing some cosmetic issues with QLabels used as
> hyperlinks. I have a form with a couple of links
> (QLabels) and each of the link opens up a modal dialog
> box. After closing the modal dialog box, the link
> remains "selected". If somebody clicks all the links,
> all of them will remain selected as long as the window
> remains open. Please see attached screenshot.
> 
> Is there a way to remove this behavior (e.g. to clear
> this selection box around the label after click or do
> something so that it never gets the selection box at
> all when clicked, but respond to the click) ?

Hi Danny,

This is indeed a bug in the Qt toolkit and I've created a task for the 
responsible parties to have this fixed. In the meantime I can provide 
you with a esthetically challenged workaround.

The problem is that the label believe it has received focus when it the 
link is activated and this state is never cleared. One certain way of 
clearing it is to "reset" the label, e.g. by clearing it and resetting 
the original text. Below I extract the current sender for the slot and 
if it is a QLabel I reset the text. The clear() is needed because trying 
to reset the exact same test will be optimized away. I know its not 
nice, but it does work around the problem.

     public void handleLink(String link) {

         QSignalEmitter sender = signalSender();

         QDialog d = new QDialog();
         d.setWindowTitle(link);
         d.exec();

         if (sender instanceof QLabel) {
             QLabel label = (QLabel) sender;
             String originalText = label.text();
             label.clear();
             label.setText(originalText);
         }

}

best regards,
Gunnar