[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KPushButton::setDelayedMenu
From:       Dominik Haumann <dhdev () gmx ! de>
Date:       2007-09-06 22:15:04
Message-ID: 200709070015.04716.dhdev () gmx ! de
[Download RAW message or body]

> > On Saturday 07 July 2007, Dominik Haumann wrote:
> > > KPushButton is pretty much broken with regard to the delayed menu
> > > capabilities. As QPushButton::setMenu is not virtual there is an
> > > additional function KPushButton::setDelayedMenu().
> > >
> > > When you hold down the button long enough a timer ticks which then
> > > adds the menu by using QPushButton::setMenu(delayed_menu).
> > >
> > > That's also the reason why KPushButton does not show the "down arrow"
> > > on the right side of the button even if you set a delayed menu. The
> > > arrow is shown when you hold down the button long enough. That means
> > > that there is no indication that the button has a delayed menu at
> > > all.

The not exported functions [re]setLayoutItemMargins (somewhere in Qt in 
gui/widgets/*) layout the icon and the text. This relayout is done without 
a menu.

The patch does 2 things:
1) sizeHint temporarily sets a menu, so the button's size is always correct
2) paintEvent temporarily sets a menu that QPushButton::painEvent draws the
   down-arrow.

However, in *both* cases the layout of the icon and the text is wrong: It is 
calculated as if the down-arrow would not exist -- when the relayouting 
stuff happens menu() returns 0, i.e. it really does not exist.

Without the patch, the user does not even have feedback that there is a 
drop-down menu. If he knows it, he gets a wrong layouted button.
With the patch, the down-arrow is there. But the layout is still always 
wrong.

Right now I don't see a solution, not even a really ugly hack. It simply 
doesn't work.

Maybe someone else can have a look?

Thanks,
Dominik

["kpushbutton.diff" (text/x-diff)]

Index: kpushbutton.cpp
===================================================================
--- kpushbutton.cpp	(Revision 709158)
+++ kpushbutton.cpp	(Arbeitskopie)
@@ -266,4 +266,32 @@
     return d->delayedMenu;
 }
 
+
+void KPushButton::paintEvent(QPaintEvent *ev)
+{
+    if (menu() || !d->delayedMenu) {
+        QPushButton::paintEvent(ev);
+    } else {
+        KPushButton *that = const_cast<KPushButton*>(this);
+        QMenu m(that);
+	that->setMenu(&m);
+	QPushButton::paintEvent(ev);
+	that->setMenu(0);
+    }
+}
+
+QSize KPushButton::sizeHint() const
+{
+    if (menu() || !d->delayedMenu) {
+        return QPushButton::sizeHint();
+    } else {
+        KPushButton *that = const_cast<KPushButton*>(this);
+        QMenu m(that);
+	that->setMenu(&m);
+	QSize sh = QPushButton::sizeHint();
+	that->setMenu(0);
+	return sh;
+    }
+}
+
 #include "kpushbutton.moc"
Index: kpushbutton.h
===================================================================
--- kpushbutton.h	(Revision 709158)
+++ kpushbutton.h	(Arbeitskopie)
@@ -125,6 +125,8 @@
      */
      QMenu *delayedMenu();
 
+    virtual QSize sizeHint() const;
+
 protected:
     /**
      * Reimplement this and return the QDrag object that should be used
@@ -148,6 +150,8 @@
      */
     virtual void startDrag();
 
+    virtual void paintEvent(QPaintEvent *);
+
 private:
     /**
      * Internal.

["kpushbutton-without-patch.png" (image/png)]
["kpushbutton-with-patch.png" (image/png)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic