Page 1 of 3 123 LastLast
Results 1 to 20 of 43

Thread: QTableWidget issues

  1. #1
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QTableWidget issues

    Hi!

    I am relatively new with Qt and trying to develop an application with two QTableWidget in it. (That is not my idea, my chief asked for it). Now, those tho qtable widget should be in one section, same context view (like there are two items in one qlistviewidget, where listwidget is scrolling for tho tables). I even have a picture what should it look like. This is the picture: http://img137.imageshack.us/my.php?image=ev3jr3.jpg
    The lower qtablewidget widget should be smaller then the upper. Whole section should be scrolling at the same time with the bigger (upper) qtablewidget. Does any of you know, how can I implement this? Should I use same widget which needs to be parent of both qtablewidgets? If that's the case, which widget I need to use? Or, plan B: the upper qtablewdiget needs to be parent of lower qtablewidget (how to implement this)? I am really clueless, and I hope I've explained what is the problem (have no idea how to implement this).

    I'll appreciate any answer, thanx!

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

    Default Re: QTableWidget issues

    I think you should start from simple things and then work your way up until you reach the exact solution. The exact arrangement of widgets can be done at later stage. You should start with syncing scrolling of those two views (which should be achievable simply by connecting appropriate signals and slots between them). When you have that, you can continue with something more complex.

  3. #3
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Yeah, I understand what you say, but I 've pretty much done all that already (I am talking about table's). But now I have issues about how I need to organize them, and what paretn widget I need to use, and how to achieve proper scrolling etc... So, thank you for your reply, but it doesn't solve my problem.

    Hm... I am reading your post again, and thinking maybe we didn't undertand each other completely. How do you think I can get widget scrolling in sync if I haven't organize them? The widgets that should be scrolling in sync are not tables, but bigger table and area in which are tables. But I don't have no idea what parent widget I need to use, nor do I now how to get everything in sync (Yes, I've heard for connecting signals and slots, but the qustion is whose signals with whose slots?).

    Sorry for my bad English, and thank you for reply

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

    Default Re: QTableWidget issues

    Quote Originally Posted by Djony View Post
    But I don't have no idea what parent widget I need to use, nor do I now how to get everything in sync
    The parent has nothing to do with it. It can be for example QWidget.

    If you're asking about the child widgets, then in general if you want to have a scrollable canvas with widgets inside, you should use QScrollArea and if you want to scroll something which is not a widget, then go for one of the views.

    (Yes, I've heard for connecting signals and slots, but the qustion is whose signals with whose slots?).
    Connect the scrollbars, so that if you move one of them, the other moves as well. It is possible that you'll need to do that through a custom slot which will scale between scrollbars as they will probably have different ranges.

  5. #5
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    When I say parent, I mean what "display object" I need to use to get tables in one area and bigger table scrolling with that area. I know it should be widget, but don't have clue what widget to use. Yo've named QScrollArea. But, correct me if I am wrong, QScrollArea can only have one child widget. Am I wright. The whole problem seems to be (at least that's my point of view at the moment) which display object to use, so tables can be shown in it as child widgets. That means, to have autoscroll, when lower table is formed (because tables are not created at the same time, lower table needs to be created when item is selected in upper table), so the user can scroll that big display object in which are tables. So, which display object to use?

    Thanx for your replies on both topics

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

    Default Re: QTableWidget issues

    Quote Originally Posted by Djony View Post
    When I say parent, I mean what "display object" I need to use to get tables in one area and bigger table scrolling with that area.
    I think I don't understand

    But, correct me if I am wrong, QScrollArea can only have one child widget. Am I wright.
    Basically you're right but in the end you're wrong - QScrollArea may have a single child widget which in turn has many-many-many child widgets of its own, resulting in the scrollarea having multiple widgets displayed in it.

    The whole problem seems to be (at least that's my point of view at the moment) which display object to use, so tables can be shown in it as child widgets.
    I still don't understand what you mean by "display object". My answer (QWidget) still stands... It is a "display object" after all...

    That means, to have autoscroll, when lower table is formed (because tables are not created at the same time, lower table needs to be created when item is selected in upper table), so the user can scroll that big display object in which are tables. So, which display object to use?
    QScrollArea?

    I think you should just open Qt Designer and start experimenting. Just remember you won't be able to place a scrollarea with child widgets directly on a form, so eventually you'll have to subclass and implement some of the details manually.

  7. #7
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    "Display object" is that big white background in which are those tables placed (look at the picture again). That's what I mean when I write "display object". If that object is QscrollArea, I can place one table in it. What to do with the lower table? And that white background should be resized when I place lower table in it. The scrollbar of that background "display object" should become longer. I hope I've explained it now

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

    Default Re: QTableWidget issues

    Quote Originally Posted by Djony View Post
    "Display object" is that big white background in which are those tables placed (look at the picture again). That's what I mean when I write "display object".
    Oh, then that's perfectly legitimate QWidget

    If that object is QscrollArea, I can place one table in it. What to do with the lower table? And that white background should be resized when I place lower table in it. The scrollbar of that background "display object" should become longer. I hope I've explained it now
    You should read about layouts...

  9. #9
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Now that I have solved some things, back to this problem Are you suggesting me to place two qtablewidgets on one layout, which would be an item of QScroll Area? (Asking just to clarify... ) But, will Layout resize itself automatically when tables get bigger (number of rows for tables is unpredictable)?

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

    Default Re: QTableWidget issues

    Please read about layouts before asking such questions

  11. #11
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Ok, I will stop with that for now (although I don't quite get it beside reading the link you gave me). Is it possible to fill cell table with colors like they are colored on picture (multiple colors, size of colored areas in proportion to percentage...)?

    P.S.
    I am wondering the same thing when we are talking about display of whole application. Is it possible to do it that way? To look and behave on described manner? Sorry for asking so much questions, but I am such a newbie

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

    Default Re: QTableWidget issues

    Quote Originally Posted by Djony View Post
    Ok, I will stop with that for now (although I don't quite get it beside reading the link you gave me). Is it possible to fill cell table with colors like they are colored on picture (multiple colors, size of colored areas in proportion to percentage...)?
    Yes. Reimplement the delegate if you want to change the looks of items in Q*{View,Widget}

    P.S.
    I am wondering the same thing when we are talking about display of whole application. Is it possible to do it that way? To look and behave on described manner? Sorry for asking so much questions, but I am such a newbie
    Yes. QPalette and/or subclassing and reimplementing paintEvents/styles/etc. are your friends.

  13. #13
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Thank you for the answer.
    If I understood you right, you mean to make class which inherits qtablewidgetitem and implement a method of that class which colors the cell in adequate manner? But, the question is, how can I control the size of areas in one cell (if you look at the picture, you will notice that there are 3 areas in one cell: green, red, blue parts). The height is the height of cells, but width? Thanx for any replies!
    Last edited by Djony; 30th November 2006 at 13:34.

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

    Default Re: QTableWidget issues

    Quote Originally Posted by Djony View Post
    If I understood you right, you mean to make class which inherits qtablewidgetitem and implement a method of that class which colors the cell in adequate manner?
    No, I meant to subclass QItemDelegate or QAbstractItemDelegate and reimplement painting and/or drawBackground routines.

    But, the question is, how can I control the size of areas in one cell (if you look at the picture, you will notice that there are 3 areas in one cell: green, red, blue parts). The height is the height of cells, but width?
    You have to reimplement the delegate's paint or drawDisplay() methods and draw the rectangles yourself.

  15. #15
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    How can I get positions and dimensions of these rectangles? They are inside table cells.

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

    Default Re: QTableWidget issues

    You get the width of the whole cell rectangle. You can then calculate lengths of each of the bars knowing the percentage to be displayed.

  17. #17
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Thanx for reply, but I don't get it completely. I am looking at some examples in Qt Assistant and I can't catch when are those methods from QItemDelegate's class child called. Where is in my case, drawDisplay() method called?

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

    Default Re: QTableWidget issues

    The delegate is used by the view to render items. So every time an item needs to be drawn, the delegate is called to do that. drawDisplay is called by paint() which in turn is called by the view.

  19. #19
    Join Date
    Nov 2006
    Posts
    72
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableWidget issues

    Quote Originally Posted by wysota View Post
    The delegate is used by the view to render items. So every time an item needs to be drawn, the delegate is called to do that. drawDisplay is called by paint() which in turn is called by the view.
    In my case, is that going to happen when I insert row in my table or when I set new QTableWidgetItem for my new cell? Should paint() be called in code, or "automatically"?

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

    Default Re: QTableWidget issues

    The delegate is called automatically whenever the view feels like repainting an item.

Similar Threads

  1. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  2. parsing QtableWidget from a QStackedWidget
    By rosmarcha in forum Qt Programming
    Replies: 10
    Last Post: 13th October 2006, 14:36
  3. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  4. Replies: 6
    Last Post: 5th March 2006, 21:05
  5. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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.