Results 1 to 9 of 9

Thread: How to get Rect or Size by QStyle?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile How to get Rect or Size by QStyle?

    Hi, all.
    I subclass QTableView and reimplement
    Qt Code:
    1. QTableView::mouseReleaseEvent(QEvent *event)
    To copy to clipboard, switch view to plain text mode 
    , in which i get
    Qt Code:
    1. QTableView::currentIndex()
    To copy to clipboard, switch view to plain text mode 
    and the event pos by
    Qt Code:
    1. event->pos()
    To copy to clipboard, switch view to plain text mode 
    before this i've set some items checkable so there is a checkbox in the responding positions.
    Now, i'm wondering how can i get the checkbox's geometry, rect or size? which is devided from the item's other part. as in the attachment, i want to know the red rectangle's rect or just size.

    By now i can get the whole item's rect through it's index and the style of this view. by the way, the view's indicator's appearence is set by a stylesheet.

    thank you.
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Rect or Size by QStyle?

    What do you want to know the size for ?

    That size is basically passed by tableview to delegate. are u using delegates ?

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

    nifei (19th November 2008)

  4. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get Rect or Size by QStyle?

    Quote Originally Posted by aamer4yu View Post
    What do you want to know the size for ?

    That size is basically passed by tableview to delegate. are u using delegates ?
    I want to know the size of the checkBox in the tableView's item, that is the rectangle displaying a checkBox, when the item is set user checkable, we could do this by calling
    Qt Code:
    1. QStandardItem::setCheckable(bool)
    To copy to clipboard, switch view to plain text mode 
    .

    I haven't used custom delegate.

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Rect or Size by QStyle?

    So what are u gonna do even if u get the rectangle of the checkbox ??

    or does QStandardItem::setCheckable(bool) solve ur prob ?

  6. #5
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get Rect or Size by QStyle?

    Quote Originally Posted by aamer4yu View Post
    So what are u gonna do even if u get the rectangle of the checkbox ??

    or does QStandardItem::setCheckable(bool) solve ur prob ?
    Qt Code:
    1. QStandardItem::setCheckable(bool)
    To copy to clipboard, switch view to plain text mode 
    can put a check box in the view's item. i can check or uncheck the checkbox by clicking it, however, i want to check or uncheck the checkbox by clicking any position of the item, including the checkbox. so I reimplement
    Qt Code:
    1. QTableView::mouseReleaseEvent(QEvent *event)
    To copy to clipboard, switch view to plain text mode 
    , and have to judge whether the mouse event position is inside or outside the check box,

    in one word: i need different operations when mouse event happens inside and outside the checkbox, so i have to know the checkbox's rect.

  7. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Rect or Size by QStyle?

    i want to check or uncheck the checkbox by clicking any position of the item, including the checkbox. so I reimplement
    QTableView::mouseReleaseEvent(QEvent *event)
    , and have to judge whether the mouse event position is inside or outside the check box,
    I dont think u need to manipulate check box area... u just need to toggle check state on mouse release event fo that index... hope am getting u rright

  8. #7
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Wink Re: How to get Rect or Size by QStyle?

    Quote Originally Posted by aamer4yu View Post
    I dont think u need to manipulate check box area... u just need to toggle check state on mouse release event fo that index... hope am getting u rright
    Yes, I implement
    Qt Code:
    1. MouseReleaseEvent(QMouseEvent *)
    To copy to clipboard, switch view to plain text mode 
    and when clicking the area of that index , besides the check box area, it works well. but when clicking the checkbox, the check box is toggled, and the mouseReleaseEvent also works, so it equals to set the check state twice! and the check box is toggled and toggled again. so i need to prevent setting the check state myself of that index when the
    Qt Code:
    1. event->pos()
    To copy to clipboard, switch view to plain text mode 
    is inside the check box.

    Thank you for answering my questions!

  9. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Rect or Size by QStyle?

    Usually icons have a size of 16x16. So u can assume checkbox to be 16 or 18 pixels wide and try ur code..
    error of 1-2 pixels wont affect much... user wont gonna hit exactly where u ain't trapping mouse press

  10. #9
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get Rect or Size by QStyle?

    Quote Originally Posted by aamer4yu View Post
    Usually icons have a size of 16x16. So u can assume checkbox to be 16 or 18 pixels wide and try ur code..
    error of 1-2 pixels wont affect much... user wont gonna hit exactly where u ain't trapping mouse press
    your advice is useful when the default style is used. however, i want to control the style of check box by Style Sheet, that is to say, the size of a check box may be different to default one. thank you.

Similar Threads

  1. QT-wince and QHttp::readAll() trouble....
    By AcerExtensa in forum Qt for Embedded and Mobile
    Replies: 6
    Last Post: 12th June 2008, 09:40
  2. adjust Font size to a given rect when drawText
    By yartov in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2008, 19:03
  3. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  4. Replies: 1
    Last Post: 24th October 2006, 16:40
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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.