Results 1 to 7 of 7

Thread: Add signals to qTextEdit

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Add signals to qTextEdit

    I have implemented a 3rd party LED widget called tled.
    Isn't your "tled" class already derived from something like QPushButton? It should already have the necessary methods for setting text, etc.

    I think you may be a bit confused between "promoting" a widget that you are using in Qt Designer and "deriving" a widget from some base class that has functionality you want to use. They are totally different concepts.

    In Qt Designer, you can lay out a user interface window (dialog, widget, whatever) and use some suitable widget as a placeholder in the GUI to stand in for a custom widget like your tled widget. After you finish the layout, you tell Qt Designer to "promote" the standard widget you have used to be your custom widget instead. All this does in practice is to update the ui file to replace the class name of the Qt widget with the class name of the custom widget and add some more UI code to import the correct header file for the custom widget when the UIC compiler runs.

    When you want to use Qt Designer promotion and you want to be able to use Qt Designer to set default values for your custom widget, you generally choose a Qt widget that has properties with the same names as those for your custom widget. Qt Designer will create UI code for the stock Qt widget you have chosen that just happens to continue to work after promotion because the custom widget has the same property. Perhaps this is why the authors of your tled widget suggested using QTextEdit as the placeholder before promotion.

    Promotion does not mean that you can magically add new properties to your custom widget by choosing a Qt widget with those properties and then promoting it. Your custom widget is what it is and you can't change it through some UI designer switcheroo.

    What you can do is to derive a new C++ class that uses your custom widget as a base class. You can then add whatever functionality you want to this new class because you're in charge. If you name new properties for this class to be the same as those used by a Qt widget (a "text" property, for example), then you can trick Qt Designer into generating the code to support that property in your new widget by choosing the appropriate Qt widget, setting the property in Designer, then promoting the Qt widget to your new widget. You have not done anything to change the programming interface for either widget. All you have done is to tell Qt Designer, "for the purposes of setting this property value, treat my custom widget as though it was this standard Qt widget instead".

    When I try to connect mousePressed to a slot I get an error saying that mousePressed is not found.
    "mousePressed()" is a Qt widget event, not a signal. You cannot connect events to slots. This will either result in a compiler error or a Qt runtime warning (depending on how the code is written). If you want to handle a mousePressed() event and be able to use that to call a slot method, then the simplest procedure is to derive a new class, add a custom signal (mousePressedSignal() for example), implement an override of the mousePressed() event, and in that handler emit your new signal. Once you have that in place, you can connect this new signal to whatever slot you want.
    Last edited by d_stranz; 28th August 2019 at 17:38.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 21st March 2017, 17:16
  2. Replies: 6
    Last Post: 29th April 2011, 15:22
  3. Replies: 1
    Last Post: 24th October 2010, 11:09
  4. QTextEdit cut copy and paste signals.
    By chris_helloworld in forum Qt Programming
    Replies: 0
    Last Post: 19th October 2010, 11:15
  5. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18

Tags for this Thread

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.