Results 1 to 5 of 5

Thread: Complex text orientation in a QTableWidget cell

  1. #1
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Complex text orientation in a QTableWidget cell

    Hi,

    I'm trying to create a custom calendar based on a QTableWidget.
    My Problem is, that I need to display text within the cells in different corners. The day number (1 - 31) should be displayed in the top left corner of the cell. That works fine using Qt Alignment to the QTableWidgetItems.
    But now I'd also like to add some text in the center of the cells and two or three icons in the top right corner, vertically orientated.

    I know, that I can't do this with pure QTableWidgetItems, so I thought of a custom QWidget that holds a separate QTableWidget, so I have maximum options to position my stuff into the cell.

    Question 1:
    Is that the right way to solve my problem? Maybe using many QWidgets/QTableWidgets inside a QTablewidget needs too much memory and results in bad performance?

    Question 2:
    Qt documentation says, QItemDelegate is a better way for displaying custom text/edit data inside cells. Can I use QItemDelegate for my purposes and if yes, should I prefer it?

    Thank you in anticipation!
    Binary

  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: Complex text orientation in a QTableWidget cell

    Quote Originally Posted by Binary91 View Post
    Qt documentation says, QItemDelegate is a better way for displaying custom text/edit data inside cells. Can I use QItemDelegate for my purposes and if yes, should I prefer it?
    Yes and yes.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Complex text orientation in a QTableWidget cell

    Hi anda_skoa,

    thank you for your answer. Well, honestly I don't understand QItemDelegate clearly. Can I use it like a QWidget as a container for other widgets?
    Is it possible for me to subclass QItemDelegate, give it a QGridLayout and position other stuff like I want to do it?

  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: Complex text orientation in a QTableWidget cell

    Quote Originally Posted by Binary91 View Post
    thank you for your answer. Well, honestly I don't understand QItemDelegate clearly. Can I use it like a QWidget as a container for other widgets?
    No, it is not a widget or a widget container.
    It is an interface that a view can delegate drawing of cells to.

    A delegate allows for fully customized drawing of cells, the view will ask it for cell dimension and at some point call its paint method.

    Drawing multiple texts into different places is just a matter of calling QPainter's drawText() method multiple times.
    Drawing icons is just a matter of calling QPainter's drawImage() or drawPixmap() methods.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2014
    Location
    Germany
    Posts
    69
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Complex text orientation in a QTableWidget cell

    Hi again,

    thank you. I will take a look at it later, but that seems to be clear...

    Cheers,

Similar Threads

  1. Replies: 3
    Last Post: 9th November 2012, 18:55
  2. text orientation in qt
    By DEEPADEV in forum Qt Programming
    Replies: 19
    Last Post: 19th June 2012, 09:52
  3. Replies: 1
    Last Post: 7th December 2009, 18:56
  4. QLineEdit text orientation
    By emrares in forum Qt Programming
    Replies: 7
    Last Post: 15th September 2009, 06:25
  5. Vertical Orientation of Text.
    By ashukla in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2008, 12:40

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.