ktoolbarlabelaction class

David Faure faure at kde.org
Sun Dec 12 19:08:56 GMT 2004


On Sunday 05 December 2004 16:27, Felix Berger wrote:
> Hi,
> 
> a couple of months ago I proposed to add the KToolbarLabelAction class to 
> kdeui.
> 
> At that time there were still some problems when a KSqueezedTextLabel is used 
> with the KToolbarLabelAction.
> 
> By overriding QLabel::setAlignment(int) in KSqueezedTextLabel I could fix this 
> problem, this also solves problems when setting a buddy for a 
> KSqueezedTextLabel, although this might not be an intended use, since it's 
> not clear if the accelerator key is visible at all.
> 
> The problem was that QLabel::setBuddy(QWidget*) called 
> QLabel::setAlignment(int) which respectively called the virtual 
> QLabel/KSqueezedTextLabel::setText(const QString&) with the squeezed text as 
> argument. Thus the original full text of the squeezed label was lost.
> 
> I've attached a tar archive which contains the ktoolbarlabelaction files, test 
> files for the ktoolbarlabelaction and a patch for the Makefile.am and 
> ksqueezedtextlabel files.

Shouldn't the squeezing be optional? I find it a bit surprising that a toolbarlabel
is necessarily squeezed. OTOH if one doesn't want squeezing then QLabel+KActionWidget
is enough and KToolbarLabelAction doesn't provide much more, does it?
OK, there's the setBackgroundMode call which might not be obvious.

The class should probably have a d pointer (although, technically,
m_label could always be turned into a d pointer later since it's not used inline).

Some minor nitpicks on the KSqueezeTextLabel patch:
-  } else {
+  }
+  else {
Not very useful change :)

+void KSqueezedTextLabel::setAlignment( int alignment)
missing space

About the line saying that setName(...) doesn't work: I guess that's because it's too late already.
How about Q_ASSERT( label->name() = "kde toolbar widget" ); instead, and mentioning
this in the docu, so that users of the class know that they have to use that name for the
widget (like Konq does).

It's cool that you included a test program btw.

> I'd also volunteer to patch all KDE applications I can find that use their 
> own/wrong/different implementation if it makes sense.

I guess konq could use it to save a few lines of code (the init() code, basically).

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list