Results 1 to 4 of 4

Thread: custom button-panel widget; subclass advice?

  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default custom button-panel widget; subclass advice?

    I need to design a custom panel that will pop-up next to some of my QPushButtons when they are mouseOver'ed. Initially, the panels will contain only 2 types of widgets: varying numbers of QPushButtons and a QSlider, although I'd like to keep open the option to include additional widgets later.

    So I figure I'll create a new BuPanel subclass... but looking over chapter 5 in "C++ GUI Programming with Qt4" I'm not sure what approach I should take. Their HexSpinBox example is a simple sub-class from QSpinBox, but in my case I'll have at least 2 primary widgets... would you recommend creating a new class derived from both QPushButton and QSlider? (or just QPushButton, and include a "class QSlider;" declaration in the header?) And will I have to include a parameter in the constructor which sets the number of buttons in a given panel?

    edit: here's an example-

    http://www.beg.utexas.edu/coastal/wrl/del/panel.png

    mousing over "shorelines" brings up the panel with buttons & slider (red triangle) to the right. User can either click buttons or drag the slider to change selection.
    Last edited by vonCZ; 11th November 2007 at 12:38.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: custom button-panel widget; subclass advice?

    I'd say that this is a regular menu and you can implement it as one... but if you insist on having a "panel", I'd suggest creating a widget containing the "panel" and use event filters installed on the widgets that are to be handled by the panel to show/hide the panel based on receving an enter/leave event. No need to subclass anything (besides QWidget, of course)...

  3. #3
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom button-panel widget; subclass advice?

    thanks Wysota- i've subclassed QWidget and have a new widget, BuPan. I've a pretty simple question about declaring pointers in my header file; the constructor contains the following:

    Qt Code:
    1. BuPanel::BuPanel(QWidget *parent, int numBu, int slid) : QWidget(parent)
    2. {
    3.  
    4. for(int a=0; a<numBu; a++)
    5. {
    6. pushB[a] = new QPushButton;
    7. //etc...
    8. }
    9. //etc...
    To copy to clipboard, switch view to plain text mode 

    and i have

    Qt Code:
    1. QPushButton *pushB[20]; //private
    To copy to clipboard, switch view to plain text mode 

    in the header. "20" is the maximum number of buttons I'll have in any panel, but most will have far fewer. Is this bad coding practice? ...to declare unnecessary pointers that won't be used/instantiated?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: custom button-panel widget; subclass advice?

    Very bad Either don't store pointers at all or use QList<QPushButton*> instead.

  5. The following user says thank you to wysota for this useful post:

    vonCZ (29th November 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.