Results 1 to 4 of 4

Thread: customized Combobox

  1. #1
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default customized Combobox

    Hi,
    i am interested to create a combo-box which should appear as shown below.
    double_combobox.png

    After "highlighting" the index_5 of first combobox i.e. "SiX_6", it should show a second combo-box near to that showing "Days".

    I have created a custom widget mycombobox, which contains the 1st combobox with data 'SiX_6', i have attached the signal of this combo box on highlight to a slot defined here, which checks if the selected index is 5, and in that slot, i am creating the 2nd combobox showing days.
    I am not able to see the 2nd combobox on screen.

    Is the way i am proceeding is correct? or what is the way to do this type of widget?

    thanks in advance.


    Qt Code:
    1. class myComboBox : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit myComboBox(QWidget *parent = 0);
    6. ~myComboBox ();
    7.  
    8. signals:
    9.  
    10. public slots:
    11. void Activate_2nd_Box(int index);
    12.  
    13. protected:
    14. QComboBox *box;
    15. QLabel *label;
    16.  
    17. };
    18.  
    19.  
    20. myComboBox::myComboBox(QWidget *parent) :
    21. QWidget(parent)
    22. {
    23. QStringList dump_data;
    24. dump_data << "ONE_1" << "TWO_2" << "THREE_3" << "FouR_4" << "FivE_5" << "SiX_6";
    25. QComboBox *doublebox = new QComboBox(this);
    26. doublebox->addItems( dump_data );
    27.  
    28.  
    29. connect(doublebox, SIGNAL(highlighted(int)), this, SLOT(Activate_2nd_Box(int)));
    30. //connect(doublebox, SIGNAL(currentIndexChanged(int)), this, SLOT(Activate_2nd_Box(int)));
    31. }
    32.  
    33. myComboBox::~myComboBox()
    34. {
    35. delete box;
    36. delete label;
    37. }
    38.  
    39. void myComboBox::Activate_2nd_Box(int index)
    40. {
    41. if(index == 5)
    42. {
    43. qDebug() << "index : "<< index << " highlighted";
    44. data << "Sunday" << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday";
    45. QComboBox *box2 = new QComboBox(this);
    46. box2->addItems( data );
    47.  
    48. box2->show();
    49. }
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 28th October 2014 at 13:27. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: customized Combobox

    The second widget in your image does not look like a combobox, but like a popup menu. See QMenu.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    5
    Qt products
    Qt5

    Default Re: customized Combobox

    Thanks for reply,

    I have managed to create the required scenario.
    I have created the first combobox having values ONE_1 till SiX_6, then i have cerated a signal and slot

    connect(this, SIGNAL(highlighted(int)), this, SLOT(Activate_2nd_Box(int)));
    slot is defined as
    void myComboBox::Activate_2nd_Box(int index)
    {
    if(index == 5)
    {
    qDebug() << "index : "<< index << " highlighted";
    QStringList data;
    data << "Sunday" << "Monday" << "Tuesday" << "Wednesday" << "Thursday" << "Friday" << "Saturday";
    QListWidget *list_days = new QListWidget ( parentWidget() );
    list_days->addItems ( data );
    list_days->move(300,100);
    list_days->resize(150,150);
    QFont font2 = list_days->font();
    font2.setPointSize(15);
    list_days->setFont(font2);
    list_days->show();
    }
    }


    This makes the QList to appear even if i remove mouse-focus from index-5.
    i want to show the QList only when mouse focuses on index 5. else it should not appear.
    How can i code this?

    Also when i am showing the above combo-box and QList , other screen should be dark or disabled how to code this?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: customized Combobox

    First: please use code tags when posting code
    Second: if you want to hide the window when the index is not 5, call its hide() methid
    Third: try window flag Qt::Popup

    Cheers,
    _

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

    SSqt5.2 (30th October 2014)

Similar Threads

  1. Problem with customized QTabWidget
    By SeanM in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2014, 18:18
  2. customized QgraphicsItems Replaceing them self
    By prasad.ece2 in forum Qt Programming
    Replies: 0
    Last Post: 31st December 2013, 09:17
  3. customized layout issue
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2008, 07:02
  4. QStyleOptionProgressBar customized
    By xEsk in forum Qt Programming
    Replies: 1
    Last Post: 11th November 2007, 17:25
  5. Customized Table
    By tunguska in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2007, 17:44

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.