Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Title Bar is Pushed to the Right in QT Dock Widget

Title Bar is Pushed to the Right in QT Dock Widget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 148 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello everyone, hope all is well! Currently, I am trying to host a QChart inside a dockWidget, and here is the code I am using (huge thanks to those who helped me out the other day) in my MainWindow file thus far:

    [MainWindow.cpp]

    QFrame *frame = new QFrame();
    
    
        QLineSeries *series = new QLineSeries();
        series->append(0, 6);
        series->append(2, 4);
        series->append(3, 8);
        series->append(7, 4);
        series->append(10, 5);
        *series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
    
        QChart *chart = new QChart();
        chart->legend()->hide();
        chart->addSeries(series);
        chart->setTitle("Line Chart Example");
    
        QChartView *chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
        chartView->setMinimumSize(600,600);
        chartView->setParent(frame);
    
        QComboBox *q = new QComboBox();
        q->setParent(frame);
        frame->setParent(ui->dockWidget);
    

    However, I have run into a problem, as the title bar is pushed to the right. Here is a picture of what I am talking about:

    Screen Shot 2021-06-28 at 11.12.19 AM.png

    I would like to have the chart (and combo box) under the title bar like one would expect. I would especially like the title box to be seen as one would normally expect; currently, the title bar window buttons (close, minimize/fullscreen buttons) are not even in the frame. What would I need to do to fix this issue?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You should add your widgets to a layout.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Don't assign parents manually. Use layouts instead. Also docks already have an internal layout so use their setWidget instead.

        In short replace this:

        QFrame *frame = new QFrame();
        
        QChartView *chartView = new QChartView(chart);
        chartView->setParent(frame);
        
        QComboBox *q = new QComboBox();
        q->setParent(frame);
        frame->setParent(ui->dockWidget);
        

        with:

        QFrame *frame = new QFrame();
        QChartView *chartView = new QChartView(chart);
        QComboBox *q = new QComboBox();
        
        QVBoxLayout* layout = new QVBoxLayout(frame);
        layout->addWidget(q);
        layout->addWidget(chartView);
        
        ui->dockWidget->setWidget(frame);
        
        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved