Results 1 to 20 of 25

Thread: How do draw a frame in QListView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    this code work
    Qt Code:
    1. QPainter painter(viewport());
    2. QPen pen(Qt::green, 10, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    3. painter.setPen(pen);
    4. painter.drawRect(rect());
    5. painter.translate(-horizontalScrollBar()->value(), -verticalScrollBar()->value());
    6. QListView::paintEvent(event);
    To copy to clipboard, switch view to plain text mode 
    but :
    1.at scrolling of list, top and bottom lines of rectangle erase.If using painter.translate identical effect
    2.rectangle paint over item

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: How do draw a frame in QListView?

    Translate first, then draw. Translating the painter after painting has no effect. The default QItemDelegate painting implementation fills items' background with QPalette::Base. That's why I told you to use a transparent brush.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    after using
    Qt Code:
    1. QPalette p = listView->palette();
    2. p.setBrush(QPalette::Base, Qt::transparent);
    3. listView->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    all ok. Thanks
    but rectangle paint over viewport of scrollView
    How i need to replace the standard border?
    QFrame:ainter() ?

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

    Default Re: How do draw a frame in QListView?

    There is no such thing as "QFrame::Painter()".

  5. #5
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    where then to draw decoration of widget - border,shade ?

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

    Default Re: How do draw a frame in QListView?

    It's drawn in the paintEvent (probably using QStyle primitives). I don't think you really wish to change that, but of course it is possible by reimplementing the event and drawing your own frame. It might be simpler to use stylesheets to substitute the frame with your border image or changing the style to draw another frame.

  7. #7
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    Can I obtain painter for parent QFrame in paintEvent method in QListView and re-draw it the way I want? If I can, how can I get it? Or do I need to create my own QFrame based on standard and create my ListView based on QListView and QFrame (class myView(QWidget *parent = 0) : public QListView, public myFrame) ?

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

    Default Re: How do draw a frame in QListView?

    You don't "obtain" a painter, you create it:
    Qt Code:
    1. void MyWidget::paintEvent(QPaintEvent *e){
    2. QPainter painter(this);
    3. painter.drawRect(...);
    4. //...
    5. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    If I use:
    Qt Code:
    1. QPainter painter(this);
    To copy to clipboard, switch view to plain text mode 
    nothing can be drawn and I get an error :

    QPainter::begin: Widget painting can only begin as a result of a paintEvent

    when cursor of the mouse enters the area of the window where widget is placed.

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

    Default Re: How do draw a frame in QListView?

    Obiously you can only create a painter in a paint event, like in the snippet I gave you in the previous post.

  11. #11
    Join Date
    Dec 2006
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    2

    Default Re: How do draw a frame in QListView?

    yes, I do exactly just like shown in your previous post. it gives me an error and draws nothing

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

    Default Re: How do draw a frame in QListView?

    Can we see the code along with the class declaration?

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 13:46
  2. Using QGLWidget paint engine to draw regular widgtes?
    By high_flyer in forum Qt Programming
    Replies: 11
    Last Post: 9th October 2006, 12:06
  3. Replies: 16
    Last Post: 7th March 2006, 15:57
  4. Multi frame management ... is it possible ?
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 25th January 2006, 10:41
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 14:45

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
  •  
Qt is a trademark of The Qt Company.