[Qt-interest] Porting Qt 3 to Qt 4

Jake Colman colman at ppllc.com
Thu Sep 2 19:21:42 CEST 2010


Thanks, Justin, for that quick reply.  Please see my comments below.

>>>>> "JN" == Justin Noel <justin at ics.com> writes:

   JN> On 09/01/2010 05:08 PM, Jake Colman wrote:

   >> 1) What replaced the QCustomMenuItem class?  I am deriving from that
   >> class but it no longer exists.
   >> 

   JN> Use QWidgetAction

Let me take a step back for a moment.

The reason I am using a QCustomMenuItem is because a checked menu item
in Motif (at least in our configuration) is supposed to be displayed
with a box that is red when checked and cleared when not.  Qt's
implementation, at least in Qt3, displayed a check instead of this box.
So I extended QPopupMenu with a insertMotifCheckItem() method to create
this custom menu item that knows how to paint itself accordingly.

Having explained all this, is there a better/different way to do this in
Qt4?  Please remember that I am trying to change as little code as
possible (at least for now) as part of this port.

   >> 2) What replaced QLineEdit::createPopupMenu()?  This method was
   >> intended to be reimplemented if you need to create a custom popup
   >> menu upon a right-click in the line edit.
   >> 

   JN> You have 3 options (All implemented in QWidget):

   JN> 1) Implement contextMenuEvent(...). Use setContextMenuPolicy(
   JN> Qt::DefaultContextMenu)

   JN> 2) You can add actions to any QWidget. Use setContextMenuPolicy(
   JN> Qt::ActionsContextMenu)

   JN> 3) Connect to the customContextMenuRequested() signal. Use
   JN> setContextMenuPolicy( Qt::CustomContextMen)

Turns out that I can use QLineEdit::createStandardContextMenu().  Since
that returns a QMenu*, I constructed a Q3PopupMenu from that QMenu and
used that instead.

   >> 3) How do I get the style's default frame width?  I used to call
   >> QStyle::defaultFrameWidth() but that method no longer exists.
   >> 
   >> 

   JN> int frameWidth = style()->pixelMetric(
   JN> QStyle::PM_DefaultFrameWidth, styleOptionPtr, widgetPtr);

   JN> I'll have to check the code for that particular metric, to see if
   JN> it even checks anything in the options class, but you could
   JN> probably pass it a bogus instance of QStyleOptionFrame.


Only the first parameter is checked for PM_DefaultFrameWidth and it is
handled by QCommonStyle.  So this works fine.

Thanks.

...Jake


-- 
Jake Colman | Director, Software Development
Principia Partners LLC
101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
e: colman at ppllc.com | w: www.principiapartners.com
Credit technology innovation awards winner 2008 and 2009




More information about the Qt-interest-old mailing list