Skip to content
  • 142k Topics
    712k Posts
    JonBJ

    @Khamza
    First to answer your question. Your new code delays the update till after the text edit has been shown. In that sense it is similar to the QTimer approach. For unknown reason you are claiming the code does not work correctly until after the text edit has been shown.

    There are cases in Qt which this is necessary. In particular sizes of widgets are not calculated till they are actually shown, so code which requires to know a size is often delayed in one of the above two fashions.

    HOWEVER I was never convinced by your assertion "The function itself is called but neither text is inserted nor block format changed:". While I could believe that possibly an operation on textCursor() might require the text edit to be shown I never thought that insertPlainText() for sure would depend on that. It should be callable any time, including e.g. during construction.

    I have now had time to create a minimal repro. Here are the 3 files:

    #include "passwordshowarea.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); PasswordShowArea w; w.show(); return a.exec(); } #ifndef PASSWORDSHOWAREA_H #define PASSWORDSHOWAREA_H #include <QTextEdit> class PasswordShowArea : public QTextEdit { Q_OBJECT public: PasswordShowArea(QWidget *parent = nullptr); private: void init(); void updateBlockFormat(); }; #endif // PASSWORDSHOWAREA_H #include <QAbstractTextDocumentLayout> #include <QTimer> #include "passwordshowarea.h" PasswordShowArea::PasswordShowArea(QWidget *parent) : QTextEdit(parent) { init(); //doesn't work updateBlockFormat(); // works - gpt4 suggest // QTimer::singleShot(0, this, &PasswordShowArea::updateBlockFormat); } void PasswordShowArea::init() { // QObject::connect(document()->documentLayout(), &QAbstractTextDocumentLayout::update, // this, &PasswordShowArea::updatePasswordShowArea); setTextColor(palette().color(QPalette::Text)); } void PasswordShowArea::updateBlockFormat() { insertPlainText("Some text"); QTextBlockFormat fmt = textCursor().blockFormat(); fmt.setTextIndent(20); fmt.setLineHeight(fontMetrics().height() * 2, QTextBlockFormat::LineDistanceHeight); fmt.setBackground(Qt::red); textCursor().mergeBlockFormat(fmt); }

    I have made couple of tiny tweaks where I did not have all of your code. I added fmt.setBackground(Qt::red); so that we had something to see. And here is what I get:

    Screenshot 2024-12-21 093554.png

    You can see that not only do I get the inserted text but I do also get the QTextBlockFormat changes. Identical if I change it to only call updateBlockFormat() on the delayed timer. Ubuntu 24.04, Qt 6.4.2.

    Sooo.... I suggest you try just this code.

  • Jobs, project showcases, announcements - anything that isn't directly development
    4k Topics
    22k Posts
    C

    On MacOS. you guys can use the below command:
    hdiutil attach qt-online-installer-macOS-x64-4.8.1.dmg
    /Volumes/qt-online-installer-macOS-x64-4.8.1/qt-online-installer-macOS-x64-4.8.1.app/Contents/MacOS/qt-online-installer-macOS-x64-4.8.1 --mirror https://qt.mirror.constant.com
    hdiutil detach /Volumes/qt-online-installer-macOS-x64-4.8.1

  • Everything related to designing and design tools

    114 Topics
    356 Posts
    D

    OK , thnx.

  • Everything related to the QA Tools

    65 Topics
    188 Posts
    H

    Similar discussion was posted previously.
    https://forum.qt.io/topic/150569/coding-squish-python-with-pycharm

  • Everything related to learning Qt.

    380 Topics
    2k Posts
    Ash_QtA

    Hey Everyone!

    Let's go through some of the new courses on Qt Academy, what updates have been made, and what to look forward to moving forward!

    Model View Delegate with QML

    Get to grips with the Model View Delegate (MVD) pattern in QML and the Qt framework, gaining the skills to manage and display complex data effectively. Through hands-on projects, you’ll explore the relationship between Models, Views, and Delegates, using Qt’s built-in and custom components to present dynamic data in a structured format. By course end, you’ll create a functional weather app that showcases real-time data interaction, integrating live weather data into an intuitive user interface.

    Basic Views in Qt Design Studio

    Take your first steps and explore the basics of Qt Design Studio, learning to navigate its UI, essential tools, and various workspaces. By course end, you’ll confidently navigate the Qt Design Studio workspace, gaining familiarity with its interface and essential tool locations. This course is ideal for newcomers to Qt Design Studio with some background in design tools.

    Creating Responsive Layouts in QML with LayoutItemProxy

    In this course, you’ll delve into Proxy Layouts, a technique for building responsive layouts in QML. Starting with an overview of responsive design principles, you’ll explore the LayoutItemProxy Type and learn to apply it in various practical scenarios. Ideal for those eager to advance their UI development skills in QML, this course covers using Proxy Layouts to create adaptable, responsive interfaces.

    This course was developed by Spyrosoft, experts in delivering successful Qt projects across industries. Published on Qt Academy with Spyrosoft’s permission, this material showcases their depth of expertise in Qt technologies, including Qt/QML, Qt 3D, and more.

    Let's Get Thready! Multithreading with Qt

    The course has been updated with new explanations and improved examples, to help you better understand atomic_flag and RAII. Some quiz questions and answers have been updated to reflect these changes.

    How to Install Qt

    Screenshots and instructions have been updated to reflect changes to the installion process.

    General Polishing

    We have been working on polishing the courses, updating the content and improving the overall experience with code examples, code snippets and quizzes based on your feedback!

    Please make sure you leave reviews on the courses you take, as it helps us improve the content and make it more relevant to you.

    More content is always in progress, we have upcoming courses on QML, Qt Design Studio, and more! We are always looking for feedback on what you would like to see, and looking for great people within the community to help us grow.

    If you want to stay in touch, visit the academy homepage and sign up for the newsletter! qt.io/academy. You can view the whole catalog here too.

    ~ Ash

  • 2k Topics
    12k Posts
    K

    It is like parent window is docked in main UI. That is my first dock window. Second is the one which need input in dialog form and should maintain parent child relationship as well. Is there any better approach, Please suggest. I just want to maintain parent child relationship and both window should be movable and both should be non modal.

  • 4k Topics
    17k Posts
    jsulmJ

    @Alien_123 said in Installation error:

    How to correct it.

    You already posted the solution by yourself:
    "You can select a different mirror for opensource metadata and downloads. The mirror can be set from terminal using option --mirror."
    So, do exactly that. More details here: https://wiki.qt.io/Online_Installer_4.x

  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k Topics
    10k Posts
    S

    @JonB said in Frequent unresponsiveness of this site:

    heroku

    Oh well, I remember that one! About two or three weeks ago I had trouble opening the webpage at all on two different days. It just wouldn't load. I used different websites to check if it was just down for me and the majority of those pages claimed that the Qt forum was up an running. Pinging forum.qt.io would would send a response from heroku. Didn't have any problems recently (no slow downs, no unresponsive/unreachable webpage).