TGComboBox

TGComboBox 继承 TGCompositeFrame, TGWidget

A combobox (also known as a drop down listbox) allows the selection
of one item out of a list of items. The selected item is visible in
a little window. To view the list of possible items one has to click
on a button on the right of the little window. This will drop down
a listbox. After selecting an item from the listbox the box will
disappear and the newly selected item will be shown in the little
window.

Selecting an item in the combobox will generate the event:
kC_COMMAND, kCM_COMBOBOX, combobox id, item id.

TGLineStyleComboBox 继承 TGComboBox
The TGLineStyleComboBox user callable and it creates a combobox for selecting the line style.

TGLineWidthComboBox 继承 TGComboBox
The TGLineWidthComboBox user callable and it creates a combobox for selecting the line width.

TGFontTypeComboBox 继承 TGComboBox
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.

class

TGComboBox

   TGComboBox(const TGWindow *p = 0, Int_t id = -1,
              UInt_t options = kHorizontalFrame | kSunkenFrame | kDoubleBorder,
              Pixel_t back = GetWhitePixel());/// Create a combo box widget.
   TGComboBox(const TGWindow *p, const char *text, Int_t id = -1,
              UInt_t options = kHorizontalFrame | kSunkenFrame | kDoubleBorder,
              Pixel_t back = GetWhitePixel());/// Create an editable combo box widget.

   virtual ~TGComboBox();/// Delete a combo box widget.

   virtual void DrawBorder();/// Draw border of combo box widget.
   virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }

   virtual Bool_t HandleButton(Event_t *event);/// Handle mouse button events in the combo box.
   virtual Bool_t HandleDoubleClick(Event_t *event);/// Handle double click in text entry.
   virtual Bool_t HandleMotion(Event_t *event);/// Handle pointer motion in text entry.
   virtual Bool_t HandleSelection(Event_t *event);/// Handle selection in text entry.
   virtual Bool_t HandleSelectionRequest(Event_t *event);/// Handle selection request in text entry.
   virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
/// Process messages generated by the listbox and forward
/// messages to the combobox message handling window. Parm2 contains
/// the id of the selected listbox entry.

   virtual void AddEntry(TGString *s, Int_t id)
                        { fListBox->AddEntry(s, id); Resize(); }
   virtual void AddEntry(const char *s, Int_t id)
                        { fListBox->AddEntry(s, id); Resize(); }
   virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
                        { fListBox->AddEntry(lbe, lhints); Resize(); }
   virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
                        { fListBox->InsertEntry(s, id, afterID); Resize(); }
   virtual void InsertEntry(const char *s, Int_t id, Int_t afterID)
                        { fListBox->InsertEntry(s, id, afterID); Resize(); }
   virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
                        { fListBox->InsertEntry(lbe, lhints, afterID); Resize(); }
   virtual void NewEntry(const char *s = "Entry")
                        { fListBox->NewEntry(s); Resize(); }       //*MENU*
   virtual void RemoveEntry(Int_t id = -1);                        //*MENU*
/// Remove entry. If id == -1, the currently selected entry is removed

   virtual void RemoveAll();                                       //*MENU*
/// Remove all entries from combo box.

   virtual void Layout();/// layout combobox
   virtual Bool_t IsTextInputEnabled() const { return (fTextEntry != 0); }
   virtual void EnableTextInput(Bool_t on);    //*TOGGLE* *GETTER=IsTextInputEnabled
/// Switch text input or readonly mode of combobox (not perfect yet).

   virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
                        { fListBox->RemoveEntries(from_ID, to_ID); }
   virtual Int_t GetNumberOfEntries() const
                        { return fListBox->GetNumberOfEntries(); }

   virtual TGListBox    *GetListBox() const { return fListBox; }
   virtual TGTextEntry  *GetTextEntry() const { return fTextEntry; }
   virtual TGLBEntry    *FindEntry(const char *s) const;/// Find entry by name.
   virtual void  Select(Int_t id, Bool_t emit = kTRUE);/// Emit signal.
/// Make the selected item visible in the combo box window
/// and emit signals according to the second parameter.

   virtual Int_t GetSelected() const { return fListBox->GetSelected(); }
   virtual TGLBEntry *GetSelectedEntry() const
                        { return fListBox->GetSelectedEntry(); }
   virtual void SetTopEntry(TGLBEntry *e, TGLayoutHints *lh);
/// Set a new combo box value (normally update of text string in
/// fSelEntry is done via fSelEntry::Update()).

   virtual void SetEnabled(Bool_t on = kTRUE);   //*TOGGLE* *GETTER=IsEnabled
/// Set state of combo box. If kTRUE=enabled, kFALSE=disabled.

   virtual Bool_t IsEnabled() const { return  fDDButton->IsEnabled(); }
   virtual void SortByName(Bool_t ascend = kTRUE)
                  { fListBox->SortByName(ascend); }            //*MENU*icon=bld_sortup.png*

   virtual void Selected(Int_t widgetId, Int_t id);                  // *SIGNAL*
   virtual void Selected(Int_t id) { Emit("Selected(Int_t)", id); }  // *SIGNAL*
   virtual void Selected(const char *txt) { Emit("Selected(char*)", txt); } // *SIGNAL*
   virtual void ReturnPressed();                                     // *SIGNAL*
/// Add new entry to combo box when return key pressed inside text entry
/// ReturnPressed signal is emitted.

   virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
/// Save a combo box widget as a C++ statement(s) on output stream out.

TGLineStyleComboBox

   TGLineStyleComboBox(const TGWindow *p = 0, Int_t id = -1,
              UInt_t options = kHorizontalFrame | kSunkenFrame | kDoubleBorder,
              Pixel_t back = GetWhitePixel());/// Create a line style combo box.

   virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
/// Save a line style combo box widget as a C++ statement(s).

TGLineWidthComboBox

   TGLineWidthComboBox(const TGWindow *p = 0, Int_t id = -1,
              UInt_t options = kHorizontalFrame | kSunkenFrame | kDoubleBorder,
              Pixel_t back = GetWhitePixel(), Bool_t none=kFALSE);
/// Create a line width combo box.
/// If "none" is equal to kTRUE the first entry is "None".

   virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
/// Save a line width combo box widget as a C++ statement(s).

TGFontTypeComboBox

   TGFontTypeComboBox(const TGWindow *p = 0, Int_t id = -1,
            UInt_t options = kHorizontalFrame | kSunkenFrame | kDoubleBorder,
            Pixel_t bask = GetWhitePixel());/// Create a text font combo box.
   virtual ~TGFontTypeComboBox();/// Text font combo box dtor.

code

#include "TGComboBox.h"

// TGComboBox
// 下拉选项
TGComboBox *fMonthBox;
fMonthBox = new TGComboBox(frame);
frame->AddFrame(fMonthBox, new TGLayoutHints(kLHintsLeft, 5, 5, 2, 2));
fMonthBox->AddEntry("AAA", 1);
fMonthBox->AddEntry("BBB", 2);
fMonthBox->AddEntry("CCC", 3);
fMonthBox->Select(1);
// fMonthBox->Resize(100, /*fYearEntry*/->GetHeight());

example

© Hongyi Wu            updated: 2018-05-14 17:18:21

results matching ""

    No results matching ""