+ Reply to Thread
Results 1 to 2 of 2

Thread: ComboBox with lines

  1. #1
    Join Date
    Oct 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default ComboBox with lines

    Hello,

    I would like to create a ComboBox for selecting different line styles. I triedto to use a delegate that uses the paint function to draw these lines. This works well for the popup list, But i want, that the user can select one line style and this line should be shown in the editor field. But here i see nothing. The delegate seems to work only in the popup list.
    How can i do this?

    Best regards
    Heiko

  2. #2
    Join Date
    Oct 2009
    Posts
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ComboBox with lines

    Hello,

    Now i found a solution. You have to derive a new ComboBox from QComboBox. In this you must overload the paintEvent. This should look like this.
    Qt Code:
    1. void MyComboBox::paintEvent(QPaintEvent * event)
    2. {
    3. QStylePainter painter(this);
    4.  
    5. // draw the combobox frame, focusrect and selected etc.
    6. initStyleOption(&opt);
    7. painter.drawComplexControl(QStyle::CC_ComboBox, opt);
    8.  
    9. // draw something in the edit
    10. QRect rect = painter.style()->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxEditField, this);
    11. // now you have the rect of the lineEdit and a painter and you can paint wathever you want.
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Braunstein for this useful post:

    San_Cou (15th January 2013)

+ Reply to Thread

Similar Threads

  1. connecting lines?
    By konvex in forum Qt Programming
    Replies: 8
    Last Post: 16th December 2008, 10:00
  2. how do i know if two lines intersect?
    By Vincenzo in forum Newbie
    Replies: 4
    Last Post: 7th November 2008, 15:23
  3. I want to get lines of text
    By newplayer in forum Qt Programming
    Replies: 11
    Last Post: 29th July 2008, 10:03
  4. QTextEdit: how to get lines?
    By claudio in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2007, 22:08
  5. Painting lines
    By therealjag in forum Newbie
    Replies: 34
    Last Post: 23rd March 2006, 23:43

Tags for this Thread

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