Results 1 to 9 of 9

Thread: QTable - paintCell() - how to do with it?

  1. #1
    Join Date
    Jul 2006
    Posts
    42
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QTable - paintCell() - how to do with it?

    Hi, hopefully, someone can help me out about the "paintCell()" issues.

    All I wanted to do is paint a few selected cells in a relatively large table.

    I have done all the seraches in the internet. All I saw were "re-implement" the paintCell(). OK I did it.

    1. I created a form - mainForm and drag a table into the form.
    2. So, in my project, I have mainform.ui mainform.ui.h and main.cpp
    3. So, how can I re-implement paintCell()? I create a class coded in the mainform.ui.h named Table which is inheriated from QTable. And re-write the paintCell() function, sounds right?
    4. Then, I pass the compiler. But, I did not pass the linker. The error message is: undefined refernce to mainform:aintCell(... ...) So, what went wrong?

    Then, I am thinking, I can pass the linker, how I can invoke this paintCell()? My table was dragged into the form and its the object of the QTable.

    I will be really appreciated if anyone can give me a clue.

    Best Regards,

    Here is the structure of my code:

    // filename: mainform.ui.h

    Qt Code:
    1. class Table::public QTable
    2. {
    3. Q_OBJECT
    4. public:
    5. void paintCell(QPainter *painter, int row, in col, const QRect &rc, bool selected, const QColorGroup &cg);
    6. };
    7.  
    8. void Table::paintCell( ... ... )
    9. {
    10. ... ...
    11. }
    To copy to clipboard, switch view to plain text mode 

    // mainform code starts here
    Qt Code:
    1. void mainform::init()
    2. {
    3. ... ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 25th March 2009 at 23:27.

  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: QTable - paintCell() - how to do with it?

    You don't call paintCell(). It's a virtual method of the table that gets called by the table itself. You have to use your subclass of QTable instead of QTable in your form, for example using the custom widgets mechanism available in Designer's menu. You need to place an instance of "Table" on the form and C++ will pick up your implementation of paintCell().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    mp33919 (26th March 2009)

  4. #3
    Join Date
    Jul 2006
    Posts
    42
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - paintCell() - how to do with it?

    Hi,

    I understand that I should use the Table object instead of QTable object. But the "problem" is "how"? When I dragged the table (i named it as colorTable) into the form, the colorTable is the object of QTable not the Table. I even tried to modify the mainform.ui, which is an html file. But as you know, my mainform can no longer be loaded.

    The only other way I could think of is to use the pointer. Should I use the Table object pointer to point to the colorTable? Will it work?

    by the way, the reason of the error during linking is because I coded the Table class inside the mainform.ui.h. After I posted the questions, I separated the Table class into table.h and table.cpp than the project can be compiled and the executable code was generated.

  5. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTable - paintCell() - how to do with it?

    when u drag the QTable..right click on it and choose "Promote to" option..there u can mention your custom table class.

  6. #5
    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: QTable - paintCell() - how to do with it?

    Quote Originally Posted by mp33919 View Post
    When I dragged the table (i named it as colorTable) into the form, the colorTable is the object of QTable not the Table.
    Did you use the Tools > Edit Custom Widgets mechanism to fake a new widget type? You should fill a dialog that pops up and if you do that correctly, there will be a new widget available in the "Custom Widgets" section of the widget toolbox.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Jul 2006
    Posts
    42
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - paintCell() - how to do with it?

    Hi, sorry, I have gone for other things for a while ...
    I am not sure what you mean about "fake a new widget type"
    I tried to use Tools > Edit Custom Widgets and I got a "green little Qt icon" and that "green little Qt icon" now is stay in my Custom Widgets section "permanently", I could not get rid of that "green little Qt icon".

    Anyway, let me understand two of your previous messages first:
    1. I have to create a custom widget maybe named Table
    2. Then, drag this Table widget into my mainform instead of QTable
    3. Since the paintCell is re-implemented in the Table widget, the Qt will pick it up automatically

    If that is correct, before I do it, may I ask you why we have to go such a lot of trouble just to paint the QTable's cells?

    Another question I have to ask, if I ever want to modify the Table custom widget, will the new modification affect every program I have used that Table custom widget. (It seems to me this "custom widget" concept is whole like Windows' Active X control.)

    Thanks for your reply. I am looking forward to read your reply.

  8. #7
    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: QTable - paintCell() - how to do with it?

    Quote Originally Posted by mp33919 View Post
    Hi, sorry, I have gone for other things for a while ...
    I am not sure what you mean about "fake a new widget type"
    I tried to use Tools > Edit Custom Widgets and I got a "green little Qt icon" and that "green little Qt icon" now is stay in my Custom Widgets section "permanently", I could not get rid of that "green little Qt icon".
    That's fine. It's the fake widget I was talking about. If you filled the data correctly in the preceding dialog, after compilation the "green little Qt icon" will be replaced by a real widget according to what you entered in the dialog.

    Anyway, let me understand two of your previous messages first:
    1. I have to create a custom widget maybe named Table
    2. Then, drag this Table widget into my mainform instead of QTable
    3. Since the paintCell is re-implemented in the Table widget, the Qt will pick it up automatically
    That's correct.

    If that is correct, before I do it, may I ask you why we have to go such a lot of trouble just to paint the QTable's cells?
    You don't have to. You can upgrade to Qt4 and do it in a much easier way. Qt3 is a 10 year old technology, remember that.

    Another question I have to ask, if I ever want to modify the Table custom widget, will the new modification affect every program I have used that Table custom widget. (It seems to me this "custom widget" concept is whole like Windows' Active X control.)
    No, it's not like ActiveX. Custom widgets are real classes that are compiled into your application as any other class and any other widget already available in Qt. The whole thing about "custom widgets" and "little green Qt icons" is that Designer doesn't know anything about your class. To be able to generate a correct source code that is later compiled it needs to know the class name, include file name, base class and maybe some other details about your class. To provide that information you can go using one of two ways.

    One is to implement a full-blown plugin for Designer which means writing code for yet another class that is then compiled as a library and dynamically loaded into Designer so that you can use the widget as any other already existing widget. But this requires some coding and is prone to errors so if you don't need full control over the widget from within Designer, you can use the second approach - just provide appropriate information about your class to Designer and it will create a fake widget representation (the green icon thingy) for you which you can place on Designer and manipulate like any other widget but it won't have properties (and looks) specific to your widget until you compile the application and the fake widget gets replaced by a real one.

    So to answer your question, if you modify your class, it won't affect applications that are already compiled. You'll have to rebuild them using the updated class to see the changes. There is an exception to this rule - if you compile your widget as a separate dynamic library (dll) and you link against the dll instead of directly embedding code for the class inside your application, updating the library will update all applications that link against it.

    ActiveX controls are loaded dynamically into your application while the application is running. Here the class is compiled into your application like any other class or is dynamically linked to it like any other library (like Qt itself).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    mp33919 (15th April 2009)

  10. #8
    Join Date
    Jul 2006
    Posts
    42
    Thanks
    13
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - paintCell() - how to do with it?

    Hi,
    Thanks for the help you gave to me.
    It sounded very logical to upgrade the Qt3.3.x to Qt4 so that I don't need to go through all the "troubles" just to paint a single cell of my QTable. I did, last few days I have my Linux Qt3.3.6 upgraded to Qt4.5. But now I got "serious" problem ... ...
    I can not "re-build" my existed project with new qtcreator (that is Qt4's IDE, right?). I did not know what to do with it.
    Then, I tried to open the one of my ui file. I got the error message as: "unable to launch /home/berlin/dev/qt-45/bin/uic3"
    and it also told me: "Please run it through uic3 -convert to convert it to Qt-4's ui format."
    I am not sure I am on the "right track" or not. I mean, is this a normal step to convert Qt3 designer project into Qt4 qtcreator project? Should I need to convert every ui file one by one or there is one single easy step to convert entired .pro to Qt4? And, is there a better "Qt4 assistant" than the Qt Creator Manual which tell me almost nothing.

    Thanks again.

  11. #9
    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: QTable - paintCell() - how to do with it?

    You have to port your project from Qt3 to Qt4. It requires some effort but it is worth it. Read the section about porting in your Qt Assistant.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    mp33919 (27th April 2009)

Similar Threads

  1. Searching a QTable
    By nategoofs in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 22:15
  2. a question about QTable
    By qtopiahooo in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 01:25
  3. QTable column stretchable with minimum Width
    By sunil.thaha in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2006, 13:17
  4. Problem with QTable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:00
  5. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:03

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.